@@ -20,93 +20,93 @@ |
||
20 | 20 | |
21 | 21 | class Term_Relation_Service extends Singleton implements Relation_Service_Interface { |
22 | 22 | |
23 | - /** |
|
24 | - * @var Type_Service |
|
25 | - */ |
|
26 | - private $term_entity_type_service; |
|
27 | - |
|
28 | - public function __construct() { |
|
29 | - parent::__construct(); |
|
30 | - $this->term_entity_type_service = Type_Service::get_instance(); |
|
31 | - } |
|
32 | - |
|
33 | - public function get_references( $subject_id, $subject_type ) { |
|
34 | - global $wpdb; |
|
35 | - |
|
36 | - $term_ids = $wpdb->get_col( |
|
37 | - $wpdb->prepare( |
|
38 | - "SELECT object_id FROM {$wpdb->prefix}wl_relation_instances WHERE subject_id = %d AND object_type = %d AND subject_type = %d", |
|
39 | - $subject_id, |
|
40 | - Object_Type_Enum::TERM, |
|
41 | - $subject_type |
|
42 | - ) |
|
43 | - ); |
|
44 | - |
|
45 | - return array_map( |
|
46 | - function ( $term_id ) { |
|
47 | - return new Term_Reference( $term_id ); |
|
48 | - }, |
|
49 | - $term_ids |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
54 | - public function get_relations_from_content( $content, $subject_type, $local_entity_uris ) { |
|
55 | - $entity_uris = Object_Relation_Service::get_entity_uris( $content ); |
|
56 | - |
|
57 | - return $this->get_relations_from_entity_uris( $subject_type, $entity_uris ); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param $term_id int Term id. |
|
62 | - */ |
|
63 | - public function get_relation_type( $term_id ) { |
|
64 | - $schema = $this->term_entity_type_service->get_schema( |
|
65 | - $term_id |
|
66 | - ); |
|
67 | - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize |
|
68 | - $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
69 | - |
|
70 | - $entity_type = str_replace( 'wl-', '', $schema['css_class'] ); |
|
71 | - foreach ( $classification_boxes as $cb ) { |
|
72 | - if ( in_array( $entity_type, $cb['registeredTypes'], true ) ) { |
|
73 | - return $cb['id']; |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - return WL_WHAT_RELATION; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @param $subject_type |
|
82 | - * @param $entity_uris |
|
83 | - * |
|
84 | - * @return false[]|Types\Relation[] |
|
85 | - */ |
|
86 | - public function get_relations_from_entity_uris( $subject_type, $entity_uris ) { |
|
87 | - $that = $this; |
|
88 | - |
|
89 | - return array_map( |
|
90 | - function ( $entity_uri ) use ( $subject_type, $that ) { |
|
91 | - |
|
92 | - try { |
|
93 | - $content = Wordpress_Term_Content_Legacy_Service::get_instance() |
|
94 | - ->get_by_entity_id( $entity_uri ); |
|
95 | - |
|
96 | - if ( ! isset( $content ) ) { |
|
97 | - return false; |
|
98 | - } |
|
99 | - |
|
100 | - $term_id = $content->get_bag()->term_id; |
|
101 | - |
|
102 | - return new Term_Relation( $term_id, $that->get_relation_type( $term_id ), $subject_type ); |
|
103 | - } catch ( \Exception $e ) { |
|
104 | - return false; |
|
105 | - } |
|
106 | - |
|
107 | - }, |
|
108 | - $entity_uris |
|
109 | - ); |
|
110 | - } |
|
23 | + /** |
|
24 | + * @var Type_Service |
|
25 | + */ |
|
26 | + private $term_entity_type_service; |
|
27 | + |
|
28 | + public function __construct() { |
|
29 | + parent::__construct(); |
|
30 | + $this->term_entity_type_service = Type_Service::get_instance(); |
|
31 | + } |
|
32 | + |
|
33 | + public function get_references( $subject_id, $subject_type ) { |
|
34 | + global $wpdb; |
|
35 | + |
|
36 | + $term_ids = $wpdb->get_col( |
|
37 | + $wpdb->prepare( |
|
38 | + "SELECT object_id FROM {$wpdb->prefix}wl_relation_instances WHERE subject_id = %d AND object_type = %d AND subject_type = %d", |
|
39 | + $subject_id, |
|
40 | + Object_Type_Enum::TERM, |
|
41 | + $subject_type |
|
42 | + ) |
|
43 | + ); |
|
44 | + |
|
45 | + return array_map( |
|
46 | + function ( $term_id ) { |
|
47 | + return new Term_Reference( $term_id ); |
|
48 | + }, |
|
49 | + $term_ids |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
54 | + public function get_relations_from_content( $content, $subject_type, $local_entity_uris ) { |
|
55 | + $entity_uris = Object_Relation_Service::get_entity_uris( $content ); |
|
56 | + |
|
57 | + return $this->get_relations_from_entity_uris( $subject_type, $entity_uris ); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param $term_id int Term id. |
|
62 | + */ |
|
63 | + public function get_relation_type( $term_id ) { |
|
64 | + $schema = $this->term_entity_type_service->get_schema( |
|
65 | + $term_id |
|
66 | + ); |
|
67 | + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize |
|
68 | + $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
69 | + |
|
70 | + $entity_type = str_replace( 'wl-', '', $schema['css_class'] ); |
|
71 | + foreach ( $classification_boxes as $cb ) { |
|
72 | + if ( in_array( $entity_type, $cb['registeredTypes'], true ) ) { |
|
73 | + return $cb['id']; |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + return WL_WHAT_RELATION; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @param $subject_type |
|
82 | + * @param $entity_uris |
|
83 | + * |
|
84 | + * @return false[]|Types\Relation[] |
|
85 | + */ |
|
86 | + public function get_relations_from_entity_uris( $subject_type, $entity_uris ) { |
|
87 | + $that = $this; |
|
88 | + |
|
89 | + return array_map( |
|
90 | + function ( $entity_uri ) use ( $subject_type, $that ) { |
|
91 | + |
|
92 | + try { |
|
93 | + $content = Wordpress_Term_Content_Legacy_Service::get_instance() |
|
94 | + ->get_by_entity_id( $entity_uri ); |
|
95 | + |
|
96 | + if ( ! isset( $content ) ) { |
|
97 | + return false; |
|
98 | + } |
|
99 | + |
|
100 | + $term_id = $content->get_bag()->term_id; |
|
101 | + |
|
102 | + return new Term_Relation( $term_id, $that->get_relation_type( $term_id ), $subject_type ); |
|
103 | + } catch ( \Exception $e ) { |
|
104 | + return false; |
|
105 | + } |
|
106 | + |
|
107 | + }, |
|
108 | + $entity_uris |
|
109 | + ); |
|
110 | + } |
|
111 | 111 | |
112 | 112 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | $this->term_entity_type_service = Type_Service::get_instance(); |
31 | 31 | } |
32 | 32 | |
33 | - public function get_references( $subject_id, $subject_type ) { |
|
33 | + public function get_references($subject_id, $subject_type) { |
|
34 | 34 | global $wpdb; |
35 | 35 | |
36 | 36 | $term_ids = $wpdb->get_col( |
@@ -43,33 +43,33 @@ discard block |
||
43 | 43 | ); |
44 | 44 | |
45 | 45 | return array_map( |
46 | - function ( $term_id ) { |
|
47 | - return new Term_Reference( $term_id ); |
|
46 | + function($term_id) { |
|
47 | + return new Term_Reference($term_id); |
|
48 | 48 | }, |
49 | 49 | $term_ids |
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
53 | 53 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
54 | - public function get_relations_from_content( $content, $subject_type, $local_entity_uris ) { |
|
55 | - $entity_uris = Object_Relation_Service::get_entity_uris( $content ); |
|
54 | + public function get_relations_from_content($content, $subject_type, $local_entity_uris) { |
|
55 | + $entity_uris = Object_Relation_Service::get_entity_uris($content); |
|
56 | 56 | |
57 | - return $this->get_relations_from_entity_uris( $subject_type, $entity_uris ); |
|
57 | + return $this->get_relations_from_entity_uris($subject_type, $entity_uris); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @param $term_id int Term id. |
62 | 62 | */ |
63 | - public function get_relation_type( $term_id ) { |
|
63 | + public function get_relation_type($term_id) { |
|
64 | 64 | $schema = $this->term_entity_type_service->get_schema( |
65 | 65 | $term_id |
66 | 66 | ); |
67 | 67 | // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize |
68 | - $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
68 | + $classification_boxes = unserialize(WL_CORE_POST_CLASSIFICATION_BOXES); |
|
69 | 69 | |
70 | - $entity_type = str_replace( 'wl-', '', $schema['css_class'] ); |
|
71 | - foreach ( $classification_boxes as $cb ) { |
|
72 | - if ( in_array( $entity_type, $cb['registeredTypes'], true ) ) { |
|
70 | + $entity_type = str_replace('wl-', '', $schema['css_class']); |
|
71 | + foreach ($classification_boxes as $cb) { |
|
72 | + if (in_array($entity_type, $cb['registeredTypes'], true)) { |
|
73 | 73 | return $cb['id']; |
74 | 74 | } |
75 | 75 | } |
@@ -83,24 +83,24 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return false[]|Types\Relation[] |
85 | 85 | */ |
86 | - public function get_relations_from_entity_uris( $subject_type, $entity_uris ) { |
|
86 | + public function get_relations_from_entity_uris($subject_type, $entity_uris) { |
|
87 | 87 | $that = $this; |
88 | 88 | |
89 | 89 | return array_map( |
90 | - function ( $entity_uri ) use ( $subject_type, $that ) { |
|
90 | + function($entity_uri) use ($subject_type, $that) { |
|
91 | 91 | |
92 | 92 | try { |
93 | 93 | $content = Wordpress_Term_Content_Legacy_Service::get_instance() |
94 | - ->get_by_entity_id( $entity_uri ); |
|
94 | + ->get_by_entity_id($entity_uri); |
|
95 | 95 | |
96 | - if ( ! isset( $content ) ) { |
|
96 | + if ( ! isset($content)) { |
|
97 | 97 | return false; |
98 | 98 | } |
99 | 99 | |
100 | 100 | $term_id = $content->get_bag()->term_id; |
101 | 101 | |
102 | - return new Term_Relation( $term_id, $that->get_relation_type( $term_id ), $subject_type ); |
|
103 | - } catch ( \Exception $e ) { |
|
102 | + return new Term_Relation($term_id, $that->get_relation_type($term_id), $subject_type); |
|
103 | + } catch (\Exception $e) { |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 |
@@ -16,44 +16,44 @@ |
||
16 | 16 | |
17 | 17 | class Object_No_Annotation_Relation_Service extends Object_Relation_Service { |
18 | 18 | |
19 | - public function get_relations_from_content( $content, $subject_type, $local_entity_uris ) { |
|
20 | - if ( ! $local_entity_uris ) { |
|
21 | - return array(); |
|
22 | - } |
|
23 | - |
|
24 | - return $this->get_relations_from_entity_uris( $subject_type, $local_entity_uris ); |
|
25 | - } |
|
26 | - |
|
27 | - public function get_references( $subject_id, $subject_type ) { |
|
28 | - /** |
|
29 | - * Object_Relation_Service encapsulates Post_Relation_Service which returns only the entities which are |
|
30 | - * not article, in case of no annotation we need to add them to analysis response, so wee need to get those entities. |
|
31 | - */ |
|
32 | - $references_without_articles = parent::get_references( $subject_id, $subject_type ); |
|
33 | - $references_with_articles = $this->get_all_entities_references( $subject_id, $subject_type ); |
|
34 | - |
|
35 | - // merge, filter and array_unique the references. |
|
36 | - return array_unique( array_filter( array_merge( $references_with_articles, $references_without_articles ) ) ); |
|
37 | - } |
|
38 | - |
|
39 | - public function get_all_entities_references( $subject_id, $subject_type ) { |
|
40 | - global $wpdb; |
|
41 | - $post_ids = $wpdb->get_col( |
|
42 | - $wpdb->prepare( |
|
43 | - "SELECT object_id FROM {$wpdb->prefix}wl_relation_instances WHERE subject_id = %d AND object_type = %d AND subject_type = %d", |
|
44 | - $subject_id, |
|
45 | - Object_Type_Enum::POST, |
|
46 | - $subject_type |
|
47 | - ) |
|
48 | - ); |
|
49 | - |
|
50 | - return array_map( |
|
51 | - function ( $term_id ) { |
|
52 | - return new Post_Reference( $term_id ); |
|
53 | - }, |
|
54 | - $post_ids |
|
55 | - ); |
|
56 | - |
|
57 | - } |
|
19 | + public function get_relations_from_content( $content, $subject_type, $local_entity_uris ) { |
|
20 | + if ( ! $local_entity_uris ) { |
|
21 | + return array(); |
|
22 | + } |
|
23 | + |
|
24 | + return $this->get_relations_from_entity_uris( $subject_type, $local_entity_uris ); |
|
25 | + } |
|
26 | + |
|
27 | + public function get_references( $subject_id, $subject_type ) { |
|
28 | + /** |
|
29 | + * Object_Relation_Service encapsulates Post_Relation_Service which returns only the entities which are |
|
30 | + * not article, in case of no annotation we need to add them to analysis response, so wee need to get those entities. |
|
31 | + */ |
|
32 | + $references_without_articles = parent::get_references( $subject_id, $subject_type ); |
|
33 | + $references_with_articles = $this->get_all_entities_references( $subject_id, $subject_type ); |
|
34 | + |
|
35 | + // merge, filter and array_unique the references. |
|
36 | + return array_unique( array_filter( array_merge( $references_with_articles, $references_without_articles ) ) ); |
|
37 | + } |
|
38 | + |
|
39 | + public function get_all_entities_references( $subject_id, $subject_type ) { |
|
40 | + global $wpdb; |
|
41 | + $post_ids = $wpdb->get_col( |
|
42 | + $wpdb->prepare( |
|
43 | + "SELECT object_id FROM {$wpdb->prefix}wl_relation_instances WHERE subject_id = %d AND object_type = %d AND subject_type = %d", |
|
44 | + $subject_id, |
|
45 | + Object_Type_Enum::POST, |
|
46 | + $subject_type |
|
47 | + ) |
|
48 | + ); |
|
49 | + |
|
50 | + return array_map( |
|
51 | + function ( $term_id ) { |
|
52 | + return new Post_Reference( $term_id ); |
|
53 | + }, |
|
54 | + $post_ids |
|
55 | + ); |
|
56 | + |
|
57 | + } |
|
58 | 58 | |
59 | 59 | } |
@@ -16,27 +16,27 @@ discard block |
||
16 | 16 | |
17 | 17 | class Object_No_Annotation_Relation_Service extends Object_Relation_Service { |
18 | 18 | |
19 | - public function get_relations_from_content( $content, $subject_type, $local_entity_uris ) { |
|
20 | - if ( ! $local_entity_uris ) { |
|
19 | + public function get_relations_from_content($content, $subject_type, $local_entity_uris) { |
|
20 | + if ( ! $local_entity_uris) { |
|
21 | 21 | return array(); |
22 | 22 | } |
23 | 23 | |
24 | - return $this->get_relations_from_entity_uris( $subject_type, $local_entity_uris ); |
|
24 | + return $this->get_relations_from_entity_uris($subject_type, $local_entity_uris); |
|
25 | 25 | } |
26 | 26 | |
27 | - public function get_references( $subject_id, $subject_type ) { |
|
27 | + public function get_references($subject_id, $subject_type) { |
|
28 | 28 | /** |
29 | 29 | * Object_Relation_Service encapsulates Post_Relation_Service which returns only the entities which are |
30 | 30 | * not article, in case of no annotation we need to add them to analysis response, so wee need to get those entities. |
31 | 31 | */ |
32 | - $references_without_articles = parent::get_references( $subject_id, $subject_type ); |
|
33 | - $references_with_articles = $this->get_all_entities_references( $subject_id, $subject_type ); |
|
32 | + $references_without_articles = parent::get_references($subject_id, $subject_type); |
|
33 | + $references_with_articles = $this->get_all_entities_references($subject_id, $subject_type); |
|
34 | 34 | |
35 | 35 | // merge, filter and array_unique the references. |
36 | - return array_unique( array_filter( array_merge( $references_with_articles, $references_without_articles ) ) ); |
|
36 | + return array_unique(array_filter(array_merge($references_with_articles, $references_without_articles))); |
|
37 | 37 | } |
38 | 38 | |
39 | - public function get_all_entities_references( $subject_id, $subject_type ) { |
|
39 | + public function get_all_entities_references($subject_id, $subject_type) { |
|
40 | 40 | global $wpdb; |
41 | 41 | $post_ids = $wpdb->get_col( |
42 | 42 | $wpdb->prepare( |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | ); |
49 | 49 | |
50 | 50 | return array_map( |
51 | - function ( $term_id ) { |
|
52 | - return new Post_Reference( $term_id ); |
|
51 | + function($term_id) { |
|
52 | + return new Post_Reference($term_id); |
|
53 | 53 | }, |
54 | 54 | $post_ids |
55 | 55 | ); |
@@ -17,64 +17,64 @@ |
||
17 | 17 | use Wordlift\Relation\Types\Relation; |
18 | 18 | |
19 | 19 | class Post_Relation_Service extends Singleton implements Relation_Service_Interface { |
20 | - /** |
|
21 | - * @var \Wordlift_Relation_Service |
|
22 | - */ |
|
23 | - private $legacy_post_relation_service; |
|
24 | - /** |
|
25 | - * @var \Wordlift_Entity_Uri_Service |
|
26 | - */ |
|
27 | - private $entity_uri_service; |
|
28 | - /** |
|
29 | - * @var \Wordlift_Entity_Service |
|
30 | - */ |
|
31 | - private $entity_service; |
|
20 | + /** |
|
21 | + * @var \Wordlift_Relation_Service |
|
22 | + */ |
|
23 | + private $legacy_post_relation_service; |
|
24 | + /** |
|
25 | + * @var \Wordlift_Entity_Uri_Service |
|
26 | + */ |
|
27 | + private $entity_uri_service; |
|
28 | + /** |
|
29 | + * @var \Wordlift_Entity_Service |
|
30 | + */ |
|
31 | + private $entity_service; |
|
32 | 32 | |
33 | - public function __construct() { |
|
34 | - parent::__construct(); |
|
35 | - $this->legacy_post_relation_service = \Wordlift_Relation_Service::get_instance(); |
|
36 | - $this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance(); |
|
37 | - $this->entity_service = \Wordlift_Entity_Service::get_instance(); |
|
38 | - } |
|
33 | + public function __construct() { |
|
34 | + parent::__construct(); |
|
35 | + $this->legacy_post_relation_service = \Wordlift_Relation_Service::get_instance(); |
|
36 | + $this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance(); |
|
37 | + $this->entity_service = \Wordlift_Entity_Service::get_instance(); |
|
38 | + } |
|
39 | 39 | |
40 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
41 | - public function get_references( $subject_id, $subject_type ) { |
|
42 | - $post_ids = $this->legacy_post_relation_service->get_objects( $subject_id, 'ids' ); |
|
40 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
41 | + public function get_references( $subject_id, $subject_type ) { |
|
42 | + $post_ids = $this->legacy_post_relation_service->get_objects( $subject_id, 'ids' ); |
|
43 | 43 | |
44 | - return array_map( |
|
45 | - function ( $post_id ) { |
|
46 | - return new Post_Reference( $post_id ); |
|
47 | - }, |
|
48 | - $post_ids |
|
49 | - ); |
|
50 | - } |
|
44 | + return array_map( |
|
45 | + function ( $post_id ) { |
|
46 | + return new Post_Reference( $post_id ); |
|
47 | + }, |
|
48 | + $post_ids |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | |
52 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
53 | - public function get_relations_from_content( $content, $subject_type, $local_entity_uris ) { |
|
54 | - $entity_uris = Object_Relation_Service::get_entity_uris( $content ); |
|
52 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
53 | + public function get_relations_from_content( $content, $subject_type, $local_entity_uris ) { |
|
54 | + $entity_uris = Object_Relation_Service::get_entity_uris( $content ); |
|
55 | 55 | |
56 | - return $this->get_relations_from_entity_uris( $subject_type, $entity_uris ); |
|
57 | - } |
|
56 | + return $this->get_relations_from_entity_uris( $subject_type, $entity_uris ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param $subject_type |
|
61 | - * @param $entity_uris |
|
62 | - * |
|
63 | - * @return false[]|Relation[] |
|
64 | - */ |
|
65 | - public function get_relations_from_entity_uris( $subject_type, $entity_uris ) { |
|
66 | - $that = $this; |
|
59 | + /** |
|
60 | + * @param $subject_type |
|
61 | + * @param $entity_uris |
|
62 | + * |
|
63 | + * @return false[]|Relation[] |
|
64 | + */ |
|
65 | + public function get_relations_from_entity_uris( $subject_type, $entity_uris ) { |
|
66 | + $that = $this; |
|
67 | 67 | |
68 | - return array_map( |
|
69 | - function ( $entity_uri ) use ( $subject_type, $that ) { |
|
70 | - $entity = $that->entity_uri_service->get_entity( $entity_uri ); |
|
71 | - if ( ! $entity ) { |
|
72 | - return false; |
|
73 | - } |
|
68 | + return array_map( |
|
69 | + function ( $entity_uri ) use ( $subject_type, $that ) { |
|
70 | + $entity = $that->entity_uri_service->get_entity( $entity_uri ); |
|
71 | + if ( ! $entity ) { |
|
72 | + return false; |
|
73 | + } |
|
74 | 74 | |
75 | - return new Post_Relation( $entity->ID, $that->entity_service->get_classification_scope_for( $entity->ID ), $subject_type ); |
|
76 | - }, |
|
77 | - $entity_uris |
|
78 | - ); |
|
79 | - } |
|
75 | + return new Post_Relation( $entity->ID, $that->entity_service->get_classification_scope_for( $entity->ID ), $subject_type ); |
|
76 | + }, |
|
77 | + $entity_uris |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | } |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
41 | - public function get_references( $subject_id, $subject_type ) { |
|
42 | - $post_ids = $this->legacy_post_relation_service->get_objects( $subject_id, 'ids' ); |
|
41 | + public function get_references($subject_id, $subject_type) { |
|
42 | + $post_ids = $this->legacy_post_relation_service->get_objects($subject_id, 'ids'); |
|
43 | 43 | |
44 | 44 | return array_map( |
45 | - function ( $post_id ) { |
|
46 | - return new Post_Reference( $post_id ); |
|
45 | + function($post_id) { |
|
46 | + return new Post_Reference($post_id); |
|
47 | 47 | }, |
48 | 48 | $post_ids |
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
52 | 52 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
53 | - public function get_relations_from_content( $content, $subject_type, $local_entity_uris ) { |
|
54 | - $entity_uris = Object_Relation_Service::get_entity_uris( $content ); |
|
53 | + public function get_relations_from_content($content, $subject_type, $local_entity_uris) { |
|
54 | + $entity_uris = Object_Relation_Service::get_entity_uris($content); |
|
55 | 55 | |
56 | - return $this->get_relations_from_entity_uris( $subject_type, $entity_uris ); |
|
56 | + return $this->get_relations_from_entity_uris($subject_type, $entity_uris); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,17 +62,17 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return false[]|Relation[] |
64 | 64 | */ |
65 | - public function get_relations_from_entity_uris( $subject_type, $entity_uris ) { |
|
65 | + public function get_relations_from_entity_uris($subject_type, $entity_uris) { |
|
66 | 66 | $that = $this; |
67 | 67 | |
68 | 68 | return array_map( |
69 | - function ( $entity_uri ) use ( $subject_type, $that ) { |
|
70 | - $entity = $that->entity_uri_service->get_entity( $entity_uri ); |
|
71 | - if ( ! $entity ) { |
|
69 | + function($entity_uri) use ($subject_type, $that) { |
|
70 | + $entity = $that->entity_uri_service->get_entity($entity_uri); |
|
71 | + if ( ! $entity) { |
|
72 | 72 | return false; |
73 | 73 | } |
74 | 74 | |
75 | - return new Post_Relation( $entity->ID, $that->entity_service->get_classification_scope_for( $entity->ID ), $subject_type ); |
|
75 | + return new Post_Relation($entity->ID, $that->entity_service->get_classification_scope_for($entity->ID), $subject_type); |
|
76 | 76 | }, |
77 | 77 | $entity_uris |
78 | 78 | ); |
@@ -16,8 +16,8 @@ |
||
16 | 16 | |
17 | 17 | class Post_Relation extends Relation { |
18 | 18 | |
19 | - public function get_object_type() { |
|
20 | - return Object_Type_Enum::POST; |
|
21 | - } |
|
19 | + public function get_object_type() { |
|
20 | + return Object_Type_Enum::POST; |
|
21 | + } |
|
22 | 22 | |
23 | 23 | } |
@@ -13,54 +13,54 @@ |
||
13 | 13 | |
14 | 14 | abstract class Relation { |
15 | 15 | |
16 | - /** |
|
17 | - * @var int |
|
18 | - */ |
|
19 | - private $id; |
|
16 | + /** |
|
17 | + * @var int |
|
18 | + */ |
|
19 | + private $id; |
|
20 | 20 | |
21 | - private $relation_type; |
|
21 | + private $relation_type; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Represents a subject type. |
|
25 | - * |
|
26 | - * @var int {@link Object_Type_Enum} |
|
27 | - */ |
|
28 | - private $subject_type; |
|
23 | + /** |
|
24 | + * Represents a subject type. |
|
25 | + * |
|
26 | + * @var int {@link Object_Type_Enum} |
|
27 | + */ |
|
28 | + private $subject_type; |
|
29 | 29 | |
30 | - public function __construct( $id, $relation_type, $subject_type ) { |
|
31 | - $this->id = $id; |
|
32 | - $this->relation_type = $relation_type; |
|
33 | - $this->subject_type = $subject_type; |
|
34 | - } |
|
30 | + public function __construct( $id, $relation_type, $subject_type ) { |
|
31 | + $this->id = $id; |
|
32 | + $this->relation_type = $relation_type; |
|
33 | + $this->subject_type = $subject_type; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Return Object id. |
|
38 | - * |
|
39 | - * @return int |
|
40 | - */ |
|
41 | - public function get_object_id() { |
|
42 | - return $this->id; |
|
43 | - } |
|
36 | + /** |
|
37 | + * Return Object id. |
|
38 | + * |
|
39 | + * @return int |
|
40 | + */ |
|
41 | + public function get_object_id() { |
|
42 | + return $this->id; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return int Represents the {@link Object_Type_Enum} |
|
47 | - */ |
|
48 | - abstract public function get_object_type(); |
|
45 | + /** |
|
46 | + * @return int Represents the {@link Object_Type_Enum} |
|
47 | + */ |
|
48 | + abstract public function get_object_type(); |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return int Represents the {@link Object_Type_Enum} |
|
52 | - */ |
|
53 | - public function get_subject_type() { |
|
54 | - return $this->subject_type; |
|
55 | - } |
|
50 | + /** |
|
51 | + * @return int Represents the {@link Object_Type_Enum} |
|
52 | + */ |
|
53 | + public function get_subject_type() { |
|
54 | + return $this->subject_type; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns relation type. |
|
59 | - * |
|
60 | - * @return string Relation type {@link WL_WHAT_RELATION} etc. |
|
61 | - */ |
|
62 | - public function get_relation_type() { |
|
63 | - return $this->relation_type; |
|
64 | - } |
|
57 | + /** |
|
58 | + * Returns relation type. |
|
59 | + * |
|
60 | + * @return string Relation type {@link WL_WHAT_RELATION} etc. |
|
61 | + */ |
|
62 | + public function get_relation_type() { |
|
63 | + return $this->relation_type; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | */ |
28 | 28 | private $subject_type; |
29 | 29 | |
30 | - public function __construct( $id, $relation_type, $subject_type ) { |
|
30 | + public function __construct($id, $relation_type, $subject_type) { |
|
31 | 31 | $this->id = $id; |
32 | 32 | $this->relation_type = $relation_type; |
33 | 33 | $this->subject_type = $subject_type; |
@@ -16,7 +16,7 @@ |
||
16 | 16 | |
17 | 17 | class Term_Relation extends Relation { |
18 | 18 | |
19 | - public function get_object_type() { |
|
20 | - return Object_Type_Enum::TERM; |
|
21 | - } |
|
19 | + public function get_object_type() { |
|
20 | + return Object_Type_Enum::TERM; |
|
21 | + } |
|
22 | 22 | } |
@@ -4,43 +4,43 @@ |
||
4 | 4 | |
5 | 5 | class Offer_Structured_Data { |
6 | 6 | |
7 | - /** |
|
8 | - * @var Shipping_Zones |
|
9 | - */ |
|
10 | - private $shipping_zones; |
|
7 | + /** |
|
8 | + * @var Shipping_Zones |
|
9 | + */ |
|
10 | + private $shipping_zones; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Offer_Structured_Data constructor. |
|
14 | - * |
|
15 | - * @param Shipping_Zones $shipping_zones |
|
16 | - */ |
|
17 | - public function __construct( $shipping_zones ) { |
|
12 | + /** |
|
13 | + * Offer_Structured_Data constructor. |
|
14 | + * |
|
15 | + * @param Shipping_Zones $shipping_zones |
|
16 | + */ |
|
17 | + public function __construct( $shipping_zones ) { |
|
18 | 18 | |
19 | - $this->shipping_zones = $shipping_zones; |
|
19 | + $this->shipping_zones = $shipping_zones; |
|
20 | 20 | |
21 | - add_filter( 'wl_entity_jsonld', array( $this, 'entity_jsonld' ), 10, 2 ); |
|
21 | + add_filter( 'wl_entity_jsonld', array( $this, 'entity_jsonld' ), 10, 2 ); |
|
22 | 22 | |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - public function entity_jsonld( $jsonld, $post_id ) { |
|
25 | + public function entity_jsonld( $jsonld, $post_id ) { |
|
26 | 26 | |
27 | - // Bail out if it's not a Product or the offers property isn't set. |
|
28 | - if ( ! in_array( 'Product', (array) $jsonld['@type'], true ) || ! isset( $jsonld['offers'] ) ) { |
|
29 | - return $jsonld; |
|
30 | - } |
|
27 | + // Bail out if it's not a Product or the offers property isn't set. |
|
28 | + if ( ! in_array( 'Product', (array) $jsonld['@type'], true ) || ! isset( $jsonld['offers'] ) ) { |
|
29 | + return $jsonld; |
|
30 | + } |
|
31 | 31 | |
32 | - if ( ! is_array( $jsonld['offers'] ) || ! is_numeric( key( $jsonld['offers'] ) ) ) { |
|
33 | - $jsonld['offers'] = array( $jsonld['offers'] ); |
|
34 | - } |
|
32 | + if ( ! is_array( $jsonld['offers'] ) || ! is_numeric( key( $jsonld['offers'] ) ) ) { |
|
33 | + $jsonld['offers'] = array( $jsonld['offers'] ); |
|
34 | + } |
|
35 | 35 | |
36 | - $product = new Product( $post_id ); |
|
36 | + $product = new Product( $post_id ); |
|
37 | 37 | |
38 | - foreach ( $jsonld['offers'] as &$offer ) { |
|
39 | - $this->shipping_zones->add_available_delivery_method( $offer ); |
|
40 | - $this->shipping_zones->add_offer_shipping_details( $offer, $product ); |
|
41 | - } |
|
38 | + foreach ( $jsonld['offers'] as &$offer ) { |
|
39 | + $this->shipping_zones->add_available_delivery_method( $offer ); |
|
40 | + $this->shipping_zones->add_offer_shipping_details( $offer, $product ); |
|
41 | + } |
|
42 | 42 | |
43 | - return $jsonld; |
|
44 | - } |
|
43 | + return $jsonld; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | } |
@@ -14,30 +14,30 @@ |
||
14 | 14 | * |
15 | 15 | * @param Shipping_Zones $shipping_zones |
16 | 16 | */ |
17 | - public function __construct( $shipping_zones ) { |
|
17 | + public function __construct($shipping_zones) { |
|
18 | 18 | |
19 | 19 | $this->shipping_zones = $shipping_zones; |
20 | 20 | |
21 | - add_filter( 'wl_entity_jsonld', array( $this, 'entity_jsonld' ), 10, 2 ); |
|
21 | + add_filter('wl_entity_jsonld', array($this, 'entity_jsonld'), 10, 2); |
|
22 | 22 | |
23 | 23 | } |
24 | 24 | |
25 | - public function entity_jsonld( $jsonld, $post_id ) { |
|
25 | + public function entity_jsonld($jsonld, $post_id) { |
|
26 | 26 | |
27 | 27 | // Bail out if it's not a Product or the offers property isn't set. |
28 | - if ( ! in_array( 'Product', (array) $jsonld['@type'], true ) || ! isset( $jsonld['offers'] ) ) { |
|
28 | + if ( ! in_array('Product', (array) $jsonld['@type'], true) || ! isset($jsonld['offers'])) { |
|
29 | 29 | return $jsonld; |
30 | 30 | } |
31 | 31 | |
32 | - if ( ! is_array( $jsonld['offers'] ) || ! is_numeric( key( $jsonld['offers'] ) ) ) { |
|
33 | - $jsonld['offers'] = array( $jsonld['offers'] ); |
|
32 | + if ( ! is_array($jsonld['offers']) || ! is_numeric(key($jsonld['offers']))) { |
|
33 | + $jsonld['offers'] = array($jsonld['offers']); |
|
34 | 34 | } |
35 | 35 | |
36 | - $product = new Product( $post_id ); |
|
36 | + $product = new Product($post_id); |
|
37 | 37 | |
38 | - foreach ( $jsonld['offers'] as &$offer ) { |
|
39 | - $this->shipping_zones->add_available_delivery_method( $offer ); |
|
40 | - $this->shipping_zones->add_offer_shipping_details( $offer, $product ); |
|
38 | + foreach ($jsonld['offers'] as &$offer) { |
|
39 | + $this->shipping_zones->add_available_delivery_method($offer); |
|
40 | + $this->shipping_zones->add_offer_shipping_details($offer, $product); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $jsonld; |
@@ -4,58 +4,58 @@ |
||
4 | 4 | |
5 | 5 | class Product { |
6 | 6 | |
7 | - /** |
|
8 | - * @var false|\WC_Product|null |
|
9 | - */ |
|
10 | - private $wc_product; |
|
7 | + /** |
|
8 | + * @var false|\WC_Product|null |
|
9 | + */ |
|
10 | + private $wc_product; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Product constructor. |
|
14 | - * |
|
15 | - * @param $post_id |
|
16 | - */ |
|
17 | - public function __construct( $post_id ) { |
|
12 | + /** |
|
13 | + * Product constructor. |
|
14 | + * |
|
15 | + * @param $post_id |
|
16 | + */ |
|
17 | + public function __construct( $post_id ) { |
|
18 | 18 | |
19 | - $this->wc_product = wc_get_product( $post_id ); |
|
19 | + $this->wc_product = wc_get_product( $post_id ); |
|
20 | 20 | |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | - public function add_handling_time( &$shipping_delivery_time ) { |
|
23 | + public function add_handling_time( &$shipping_delivery_time ) { |
|
24 | 24 | |
25 | - // Bail out if there's no product. |
|
26 | - if ( empty( $this->wc_product ) ) { |
|
27 | - return; |
|
28 | - } |
|
25 | + // Bail out if there's no product. |
|
26 | + if ( empty( $this->wc_product ) ) { |
|
27 | + return; |
|
28 | + } |
|
29 | 29 | |
30 | - $shipping_class_id = $this->wc_product->get_shipping_class_id(); |
|
30 | + $shipping_class_id = $this->wc_product->get_shipping_class_id(); |
|
31 | 31 | |
32 | - $option = get_option( 'wpsso_options' ); |
|
32 | + $option = get_option( 'wpsso_options' ); |
|
33 | 33 | |
34 | - if ( empty( $option[ "wcsdt_handling_c{$shipping_class_id}_unit_code" ] ) |
|
35 | - || empty( $option[ "wcsdt_handling_c{$shipping_class_id}_minimum" ] ) |
|
36 | - || empty( $option[ "wcsdt_handling_c{$shipping_class_id}_maximum" ] ) ) { |
|
37 | - return; |
|
38 | - } |
|
34 | + if ( empty( $option[ "wcsdt_handling_c{$shipping_class_id}_unit_code" ] ) |
|
35 | + || empty( $option[ "wcsdt_handling_c{$shipping_class_id}_minimum" ] ) |
|
36 | + || empty( $option[ "wcsdt_handling_c{$shipping_class_id}_maximum" ] ) ) { |
|
37 | + return; |
|
38 | + } |
|
39 | 39 | |
40 | - $unit_code = $option[ "wcsdt_handling_c{$shipping_class_id}_unit_code" ]; |
|
41 | - $minimum = $option[ "wcsdt_handling_c{$shipping_class_id}_minimum" ]; |
|
42 | - $maximum = $option[ "wcsdt_handling_c{$shipping_class_id}_maximum" ]; |
|
40 | + $unit_code = $option[ "wcsdt_handling_c{$shipping_class_id}_unit_code" ]; |
|
41 | + $minimum = $option[ "wcsdt_handling_c{$shipping_class_id}_minimum" ]; |
|
42 | + $maximum = $option[ "wcsdt_handling_c{$shipping_class_id}_maximum" ]; |
|
43 | 43 | |
44 | - if ( 'HUR' === $unit_code ) { |
|
45 | - $minimum = floor( $minimum / 24.0 ); |
|
46 | - $maximum = ceil( $maximum / 24.0 ); |
|
47 | - } |
|
44 | + if ( 'HUR' === $unit_code ) { |
|
45 | + $minimum = floor( $minimum / 24.0 ); |
|
46 | + $maximum = ceil( $maximum / 24.0 ); |
|
47 | + } |
|
48 | 48 | |
49 | - $shipping_delivery_time['handlingTime'] = array( |
|
50 | - '@type' => 'QuantitativeValue', |
|
51 | - 'minValue' => $minimum, |
|
52 | - 'maxValue' => $maximum, |
|
53 | - ); |
|
49 | + $shipping_delivery_time['handlingTime'] = array( |
|
50 | + '@type' => 'QuantitativeValue', |
|
51 | + 'minValue' => $minimum, |
|
52 | + 'maxValue' => $maximum, |
|
53 | + ); |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - private function get_handling_time() { |
|
57 | + private function get_handling_time() { |
|
58 | 58 | |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | 61 | } |
@@ -14,36 +14,36 @@ |
||
14 | 14 | * |
15 | 15 | * @param $post_id |
16 | 16 | */ |
17 | - public function __construct( $post_id ) { |
|
17 | + public function __construct($post_id) { |
|
18 | 18 | |
19 | - $this->wc_product = wc_get_product( $post_id ); |
|
19 | + $this->wc_product = wc_get_product($post_id); |
|
20 | 20 | |
21 | 21 | } |
22 | 22 | |
23 | - public function add_handling_time( &$shipping_delivery_time ) { |
|
23 | + public function add_handling_time(&$shipping_delivery_time) { |
|
24 | 24 | |
25 | 25 | // Bail out if there's no product. |
26 | - if ( empty( $this->wc_product ) ) { |
|
26 | + if (empty($this->wc_product)) { |
|
27 | 27 | return; |
28 | 28 | } |
29 | 29 | |
30 | 30 | $shipping_class_id = $this->wc_product->get_shipping_class_id(); |
31 | 31 | |
32 | - $option = get_option( 'wpsso_options' ); |
|
32 | + $option = get_option('wpsso_options'); |
|
33 | 33 | |
34 | - if ( empty( $option[ "wcsdt_handling_c{$shipping_class_id}_unit_code" ] ) |
|
35 | - || empty( $option[ "wcsdt_handling_c{$shipping_class_id}_minimum" ] ) |
|
36 | - || empty( $option[ "wcsdt_handling_c{$shipping_class_id}_maximum" ] ) ) { |
|
34 | + if (empty($option["wcsdt_handling_c{$shipping_class_id}_unit_code"]) |
|
35 | + || empty($option["wcsdt_handling_c{$shipping_class_id}_minimum"]) |
|
36 | + || empty($option["wcsdt_handling_c{$shipping_class_id}_maximum"])) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | 39 | |
40 | - $unit_code = $option[ "wcsdt_handling_c{$shipping_class_id}_unit_code" ]; |
|
41 | - $minimum = $option[ "wcsdt_handling_c{$shipping_class_id}_minimum" ]; |
|
42 | - $maximum = $option[ "wcsdt_handling_c{$shipping_class_id}_maximum" ]; |
|
40 | + $unit_code = $option["wcsdt_handling_c{$shipping_class_id}_unit_code"]; |
|
41 | + $minimum = $option["wcsdt_handling_c{$shipping_class_id}_minimum"]; |
|
42 | + $maximum = $option["wcsdt_handling_c{$shipping_class_id}_maximum"]; |
|
43 | 43 | |
44 | - if ( 'HUR' === $unit_code ) { |
|
45 | - $minimum = floor( $minimum / 24.0 ); |
|
46 | - $maximum = ceil( $maximum / 24.0 ); |
|
44 | + if ('HUR' === $unit_code) { |
|
45 | + $minimum = floor($minimum / 24.0); |
|
46 | + $maximum = ceil($maximum / 24.0); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | $shipping_delivery_time['handlingTime'] = array( |
@@ -6,81 +6,81 @@ |
||
6 | 6 | |
7 | 7 | class Shipping_Zones { |
8 | 8 | |
9 | - /** |
|
10 | - * @var Shipping_Zone[] |
|
11 | - */ |
|
12 | - private $zones; |
|
9 | + /** |
|
10 | + * @var Shipping_Zone[] |
|
11 | + */ |
|
12 | + private $zones; |
|
13 | 13 | |
14 | - public function __construct() { |
|
15 | - $this->zones = array(); |
|
16 | - } |
|
14 | + public function __construct() { |
|
15 | + $this->zones = array(); |
|
16 | + } |
|
17 | 17 | |
18 | - private function load_zones() { |
|
18 | + private function load_zones() { |
|
19 | 19 | |
20 | - $zone_ids = array_keys( WC_Shipping_Zones::get_zones() ); |
|
21 | - $wc_shipping_zones = array( WC_Shipping_Zones::get_zone( 0 ) ); |
|
22 | - foreach ( $zone_ids as $zone_id ) { |
|
23 | - $wc_shipping_zones[] = WC_Shipping_Zones::get_zone( $zone_id ); |
|
24 | - } |
|
20 | + $zone_ids = array_keys( WC_Shipping_Zones::get_zones() ); |
|
21 | + $wc_shipping_zones = array( WC_Shipping_Zones::get_zone( 0 ) ); |
|
22 | + foreach ( $zone_ids as $zone_id ) { |
|
23 | + $wc_shipping_zones[] = WC_Shipping_Zones::get_zone( $zone_id ); |
|
24 | + } |
|
25 | 25 | |
26 | - $zones = array(); |
|
27 | - foreach ( $wc_shipping_zones as $wc_shipping_zone ) { |
|
28 | - $country_codes = $this->get_country_codes( $wc_shipping_zone->get_zone_locations() ); |
|
26 | + $zones = array(); |
|
27 | + foreach ( $wc_shipping_zones as $wc_shipping_zone ) { |
|
28 | + $country_codes = $this->get_country_codes( $wc_shipping_zone->get_zone_locations() ); |
|
29 | 29 | |
30 | - if ( empty( $country_codes ) ) { |
|
31 | - $zones[] = Shipping_Zone::from_wc_shipping_zone( $wc_shipping_zone ); |
|
32 | - } else { |
|
33 | - foreach ( $country_codes as $country_code ) { |
|
34 | - $zones[] = Shipping_Zone::from_wc_shipping_zone( $wc_shipping_zone, $country_code ); |
|
35 | - } |
|
36 | - } |
|
37 | - } |
|
30 | + if ( empty( $country_codes ) ) { |
|
31 | + $zones[] = Shipping_Zone::from_wc_shipping_zone( $wc_shipping_zone ); |
|
32 | + } else { |
|
33 | + foreach ( $country_codes as $country_code ) { |
|
34 | + $zones[] = Shipping_Zone::from_wc_shipping_zone( $wc_shipping_zone, $country_code ); |
|
35 | + } |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - $this->zones = $zones; |
|
39 | + $this->zones = $zones; |
|
40 | 40 | |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - public function add_available_delivery_method( &$jsonld ) { |
|
43 | + public function add_available_delivery_method( &$jsonld ) { |
|
44 | 44 | |
45 | - $this->load_zones(); |
|
45 | + $this->load_zones(); |
|
46 | 46 | |
47 | - foreach ( $this->zones as $zone ) { |
|
48 | - $zone->add_available_delivery_method( $jsonld ); |
|
49 | - } |
|
47 | + foreach ( $this->zones as $zone ) { |
|
48 | + $zone->add_available_delivery_method( $jsonld ); |
|
49 | + } |
|
50 | 50 | |
51 | - } |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param array $jsonld |
|
55 | - * @param Product $product |
|
56 | - */ |
|
57 | - public function add_offer_shipping_details( &$jsonld, $product ) { |
|
53 | + /** |
|
54 | + * @param array $jsonld |
|
55 | + * @param Product $product |
|
56 | + */ |
|
57 | + public function add_offer_shipping_details( &$jsonld, $product ) { |
|
58 | 58 | |
59 | - $this->load_zones(); |
|
59 | + $this->load_zones(); |
|
60 | 60 | |
61 | - foreach ( $this->zones as $zone ) { |
|
62 | - $zone->add_offer_shipping_details( $jsonld, $product ); |
|
63 | - } |
|
61 | + foreach ( $this->zones as $zone ) { |
|
62 | + $zone->add_offer_shipping_details( $jsonld, $product ); |
|
63 | + } |
|
64 | 64 | |
65 | - } |
|
65 | + } |
|
66 | 66 | |
67 | - private function get_country_codes( $wc_shipping_zones ) { |
|
68 | - $countries = array(); |
|
67 | + private function get_country_codes( $wc_shipping_zones ) { |
|
68 | + $countries = array(); |
|
69 | 69 | |
70 | - foreach ( $wc_shipping_zones as $wc_shipping_zone ) { |
|
71 | - if ( ! isset( $wc_shipping_zone->type ) |
|
72 | - || ( 'country' !== $wc_shipping_zone->type && 'state' !== $wc_shipping_zone->type ) ) { |
|
73 | - continue; |
|
74 | - } |
|
70 | + foreach ( $wc_shipping_zones as $wc_shipping_zone ) { |
|
71 | + if ( ! isset( $wc_shipping_zone->type ) |
|
72 | + || ( 'country' !== $wc_shipping_zone->type && 'state' !== $wc_shipping_zone->type ) ) { |
|
73 | + continue; |
|
74 | + } |
|
75 | 75 | |
76 | - $country = substr( $wc_shipping_zone->code, 0, 2 ); |
|
76 | + $country = substr( $wc_shipping_zone->code, 0, 2 ); |
|
77 | 77 | |
78 | - if ( ! in_array( $country, $countries, true ) ) { |
|
79 | - $countries[] = $country; |
|
80 | - } |
|
81 | - } |
|
78 | + if ( ! in_array( $country, $countries, true ) ) { |
|
79 | + $countries[] = $country; |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - return $countries; |
|
84 | - } |
|
83 | + return $countries; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | } |
@@ -17,21 +17,21 @@ discard block |
||
17 | 17 | |
18 | 18 | private function load_zones() { |
19 | 19 | |
20 | - $zone_ids = array_keys( WC_Shipping_Zones::get_zones() ); |
|
21 | - $wc_shipping_zones = array( WC_Shipping_Zones::get_zone( 0 ) ); |
|
22 | - foreach ( $zone_ids as $zone_id ) { |
|
23 | - $wc_shipping_zones[] = WC_Shipping_Zones::get_zone( $zone_id ); |
|
20 | + $zone_ids = array_keys(WC_Shipping_Zones::get_zones()); |
|
21 | + $wc_shipping_zones = array(WC_Shipping_Zones::get_zone(0)); |
|
22 | + foreach ($zone_ids as $zone_id) { |
|
23 | + $wc_shipping_zones[] = WC_Shipping_Zones::get_zone($zone_id); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | $zones = array(); |
27 | - foreach ( $wc_shipping_zones as $wc_shipping_zone ) { |
|
28 | - $country_codes = $this->get_country_codes( $wc_shipping_zone->get_zone_locations() ); |
|
27 | + foreach ($wc_shipping_zones as $wc_shipping_zone) { |
|
28 | + $country_codes = $this->get_country_codes($wc_shipping_zone->get_zone_locations()); |
|
29 | 29 | |
30 | - if ( empty( $country_codes ) ) { |
|
31 | - $zones[] = Shipping_Zone::from_wc_shipping_zone( $wc_shipping_zone ); |
|
30 | + if (empty($country_codes)) { |
|
31 | + $zones[] = Shipping_Zone::from_wc_shipping_zone($wc_shipping_zone); |
|
32 | 32 | } else { |
33 | - foreach ( $country_codes as $country_code ) { |
|
34 | - $zones[] = Shipping_Zone::from_wc_shipping_zone( $wc_shipping_zone, $country_code ); |
|
33 | + foreach ($country_codes as $country_code) { |
|
34 | + $zones[] = Shipping_Zone::from_wc_shipping_zone($wc_shipping_zone, $country_code); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | } |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | - public function add_available_delivery_method( &$jsonld ) { |
|
43 | + public function add_available_delivery_method(&$jsonld) { |
|
44 | 44 | |
45 | 45 | $this->load_zones(); |
46 | 46 | |
47 | - foreach ( $this->zones as $zone ) { |
|
48 | - $zone->add_available_delivery_method( $jsonld ); |
|
47 | + foreach ($this->zones as $zone) { |
|
48 | + $zone->add_available_delivery_method($jsonld); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | } |
@@ -54,28 +54,28 @@ discard block |
||
54 | 54 | * @param array $jsonld |
55 | 55 | * @param Product $product |
56 | 56 | */ |
57 | - public function add_offer_shipping_details( &$jsonld, $product ) { |
|
57 | + public function add_offer_shipping_details(&$jsonld, $product) { |
|
58 | 58 | |
59 | 59 | $this->load_zones(); |
60 | 60 | |
61 | - foreach ( $this->zones as $zone ) { |
|
62 | - $zone->add_offer_shipping_details( $jsonld, $product ); |
|
61 | + foreach ($this->zones as $zone) { |
|
62 | + $zone->add_offer_shipping_details($jsonld, $product); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | } |
66 | 66 | |
67 | - private function get_country_codes( $wc_shipping_zones ) { |
|
67 | + private function get_country_codes($wc_shipping_zones) { |
|
68 | 68 | $countries = array(); |
69 | 69 | |
70 | - foreach ( $wc_shipping_zones as $wc_shipping_zone ) { |
|
71 | - if ( ! isset( $wc_shipping_zone->type ) |
|
72 | - || ( 'country' !== $wc_shipping_zone->type && 'state' !== $wc_shipping_zone->type ) ) { |
|
70 | + foreach ($wc_shipping_zones as $wc_shipping_zone) { |
|
71 | + if ( ! isset($wc_shipping_zone->type) |
|
72 | + || ('country' !== $wc_shipping_zone->type && 'state' !== $wc_shipping_zone->type)) { |
|
73 | 73 | continue; |
74 | 74 | } |
75 | 75 | |
76 | - $country = substr( $wc_shipping_zone->code, 0, 2 ); |
|
76 | + $country = substr($wc_shipping_zone->code, 0, 2); |
|
77 | 77 | |
78 | - if ( ! in_array( $country, $countries, true ) ) { |
|
78 | + if ( ! in_array($country, $countries, true)) { |
|
79 | 79 | $countries[] = $country; |
80 | 80 | } |
81 | 81 | } |