@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class Post_Entity_Match_Service extends Match_Service { |
| 10 | 10 | |
| 11 | - public function list_items( $args ) { |
|
| 11 | + public function list_items($args) { |
|
| 12 | 12 | global $wpdb; |
| 13 | 13 | |
| 14 | 14 | $params = wp_parse_args( |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @var $sort Sort |
| 29 | 29 | */ |
| 30 | - $sort = new Sort( $params['sort'] ); |
|
| 30 | + $sort = new Sort($params['sort']); |
|
| 31 | 31 | |
| 32 | 32 | $query_builder = new Query_Builder( |
| 33 | 33 | $params, |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | $items = $wpdb->get_results( |
| 38 | 38 | // Each function above is preparing `$sql` by using `$wpdb->prepare`. |
| 39 | 39 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 40 | - $wpdb->prepare( $query_builder->get(), Object_Type_Enum::POST ) |
|
| 40 | + $wpdb->prepare($query_builder->get(), Object_Type_Enum::POST) |
|
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | - $sort->apply( $items ); |
|
| 43 | + $sort->apply($items); |
|
| 44 | 44 | |
| 45 | - return $this->map( $items ); |
|
| 45 | + return $this->map($items); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** Returns an array of rows where each row contains |
@@ -59,20 +59,20 @@ discard block |
||
| 59 | 59 | * 'match_jsonld' => The matched `about_jsonld` column from wl_entities. |
| 60 | 60 | * 'match_id' => This id points to id column of wl_entities table. |
| 61 | 61 | */ |
| 62 | - private function map( array $items ) { |
|
| 62 | + private function map(array $items) { |
|
| 63 | 63 | return array_map( |
| 64 | - function ( $item ) { |
|
| 65 | - $data = json_decode( $item->match_jsonld, true ); |
|
| 66 | - $item->match_name = $data && is_array( $data ) && array_key_exists( 'name', $data ) ? $data['name'] : null; |
|
| 64 | + function($item) { |
|
| 65 | + $data = json_decode($item->match_jsonld, true); |
|
| 66 | + $item->match_name = $data && is_array($data) && array_key_exists('name', $data) ? $data['name'] : null; |
|
| 67 | 67 | |
| 68 | - if ( $item->id ) { |
|
| 69 | - $item->post_link = get_edit_post_link( $item->id, 'ui' ); |
|
| 70 | - $item->view_link = get_permalink( $item->id ); |
|
| 71 | - $item->preview_link = get_preview_post_link( $item->id ); |
|
| 68 | + if ($item->id) { |
|
| 69 | + $item->post_link = get_edit_post_link($item->id, 'ui'); |
|
| 70 | + $item->view_link = get_permalink($item->id); |
|
| 71 | + $item->preview_link = get_preview_post_link($item->id); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ( $item->parent_post_id ) { |
|
| 75 | - $item->parent_post_link = get_edit_post_link( $item->parent_post_id, 'ui' ); |
|
| 74 | + if ($item->parent_post_id) { |
|
| 75 | + $item->parent_post_link = get_edit_post_link($item->parent_post_id, 'ui'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | return $item; |
@@ -61,16 +61,16 @@ discard block |
||
| 61 | 61 | global $wpdb; |
| 62 | 62 | |
| 63 | 63 | // If a value has been provided and it's either 'draft' or 'publish', we add the related filter. |
| 64 | - if ( is_string( $this->params['post_status'] ) && in_array( |
|
| 64 | + if (is_string($this->params['post_status']) && in_array( |
|
| 65 | 65 | $this->params['post_status'], |
| 66 | 66 | array( |
| 67 | 67 | 'publish', |
| 68 | 68 | 'draft', |
| 69 | 69 | ), |
| 70 | 70 | true |
| 71 | - ) ) { |
|
| 71 | + )) { |
|
| 72 | 72 | |
| 73 | - $this->sql .= $wpdb->prepare( ' AND p.post_status = %s', $this->params['post_status'] ); |
|
| 73 | + $this->sql .= $wpdb->prepare(' AND p.post_status = %s', $this->params['post_status']); |
|
| 74 | 74 | |
| 75 | 75 | return $this; |
| 76 | 76 | } |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | public function post_type() { |
| 85 | 85 | $post_types = $this->params['post_types']; |
| 86 | 86 | |
| 87 | - if ( ! isset( $post_types ) ) { |
|
| 87 | + if ( ! isset($post_types)) { |
|
| 88 | 88 | return $this; |
| 89 | 89 | } |
| 90 | - $post_types_sql = Escape::sql_array( $post_types ); |
|
| 90 | + $post_types_sql = Escape::sql_array($post_types); |
|
| 91 | 91 | $this->sql .= " AND p.post_type IN ({$post_types_sql}) "; |
| 92 | 92 | |
| 93 | 93 | return $this; |
@@ -17,10 +17,10 @@ |
||
| 17 | 17 | * @return string |
| 18 | 18 | */ |
| 19 | 19 | public function get_field_name() { |
| 20 | - $tmp_sort_field_name = substr( $this->sort, 1 ); |
|
| 21 | - if ( 'id' === $tmp_sort_field_name ) { |
|
| 20 | + $tmp_sort_field_name = substr($this->sort, 1); |
|
| 21 | + if ('id' === $tmp_sort_field_name) { |
|
| 22 | 22 | return 'p.ID'; |
| 23 | - } elseif ( 'date_modified_gmt' === $tmp_sort_field_name ) { |
|
| 23 | + } elseif ('date_modified_gmt' === $tmp_sort_field_name) { |
|
| 24 | 24 | return 'p.post_modified_gmt'; |
| 25 | 25 | } else { |
| 26 | 26 | return 'p.post_title'; |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * |
| 28 | 28 | * @param Post_Entity_Match_Service $match_service |
| 29 | 29 | */ |
| 30 | - public function __construct( $match_service ) { |
|
| 30 | + public function __construct($match_service) { |
|
| 31 | 31 | $this->match_service = $match_service; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * Register hooks. |
| 36 | 36 | */ |
| 37 | 37 | public function register_hooks() { |
| 38 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
| 38 | + add_action('rest_api_init', array($this, 'register_routes')); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | '/post-matches', |
| 50 | 50 | array( |
| 51 | 51 | 'methods' => 'GET', |
| 52 | - 'callback' => array( $this, 'get_post_matches' ), |
|
| 52 | + 'callback' => array($this, 'get_post_matches'), |
|
| 53 | 53 | 'args' => array( |
| 54 | 54 | 'cursor' => array( |
| 55 | 55 | 'type' => 'string', |
| 56 | 56 | 'default' => Cursor::EMPTY_CURSOR_AS_BASE64_STRING, |
| 57 | 57 | 'validate_callback' => 'rest_validate_request_arg', |
| 58 | - 'sanitize_callback' => array( Cursor::class, 'rest_sanitize_request_arg' ), |
|
| 58 | + 'sanitize_callback' => array(Cursor::class, 'rest_sanitize_request_arg'), |
|
| 59 | 59 | ), |
| 60 | 60 | 'limit' => array( |
| 61 | 61 | 'type' => 'integer', |
@@ -77,19 +77,19 @@ discard block |
||
| 77 | 77 | 'post_status' => array( |
| 78 | 78 | 'type' => 'string', |
| 79 | 79 | 'required' => false, |
| 80 | - 'enum' => array( 'publish', 'draft' ), |
|
| 80 | + 'enum' => array('publish', 'draft'), |
|
| 81 | 81 | 'validate_callback' => 'rest_validate_request_arg', |
| 82 | 82 | ), |
| 83 | 83 | 'sort' => array( |
| 84 | 84 | 'type' => 'string', |
| 85 | 85 | 'required' => false, |
| 86 | - 'enum' => array( '+date_modified_gmt', '-date_modified_gmt' ), |
|
| 86 | + 'enum' => array('+date_modified_gmt', '-date_modified_gmt'), |
|
| 87 | 87 | 'validate_callback' => 'rest_validate_request_arg', |
| 88 | 88 | 'default' => '+date_modified_gmt', |
| 89 | 89 | ), |
| 90 | 90 | ), |
| 91 | - 'permission_callback' => function () { |
|
| 92 | - return current_user_can( 'manage_options' ); |
|
| 91 | + 'permission_callback' => function() { |
|
| 92 | + return current_user_can('manage_options'); |
|
| 93 | 93 | }, |
| 94 | 94 | ) |
| 95 | 95 | ); |
@@ -100,15 +100,15 @@ discard block |
||
| 100 | 100 | '/post-matches/(?P<post_id>\d+)/matches', |
| 101 | 101 | array( |
| 102 | 102 | 'methods' => 'POST', |
| 103 | - 'callback' => array( $this, 'create_post_match' ), |
|
| 103 | + 'callback' => array($this, 'create_post_match'), |
|
| 104 | 104 | 'args' => array( |
| 105 | 105 | 'post_id' => array( |
| 106 | 106 | 'required' => true, |
| 107 | 107 | 'validate_callback' => 'rest_validate_request_arg', |
| 108 | 108 | ), |
| 109 | 109 | ), |
| 110 | - 'permission_callback' => function () { |
|
| 111 | - return current_user_can( 'manage_options' ); |
|
| 110 | + 'permission_callback' => function() { |
|
| 111 | + return current_user_can('manage_options'); |
|
| 112 | 112 | }, |
| 113 | 113 | ) |
| 114 | 114 | ); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | '/post-matches/(?P<post_id>\d+)/matches/(?P<match_id>\d+)', |
| 120 | 120 | array( |
| 121 | 121 | 'methods' => 'PUT', |
| 122 | - 'callback' => array( $this, 'update_post_match' ), |
|
| 122 | + 'callback' => array($this, 'update_post_match'), |
|
| 123 | 123 | 'args' => array( |
| 124 | 124 | 'post_id' => array( |
| 125 | 125 | 'required' => true, |
@@ -130,9 +130,9 @@ discard block |
||
| 130 | 130 | 'validate_callback' => 'rest_validate_request_arg', |
| 131 | 131 | ), |
| 132 | 132 | ), |
| 133 | - 'permission_callback' => function () { |
|
| 133 | + 'permission_callback' => function() { |
|
| 134 | 134 | |
| 135 | - return current_user_can( 'manage_options' ); |
|
| 135 | + return current_user_can('manage_options'); |
|
| 136 | 136 | }, |
| 137 | 137 | ) |
| 138 | 138 | ); |
@@ -143,36 +143,36 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @var $request \WP_REST_Request |
| 145 | 145 | */ |
| 146 | - public function get_post_matches( $request ) { |
|
| 146 | + public function get_post_matches($request) { |
|
| 147 | 147 | |
| 148 | - $cursor = $request->get_param( 'cursor' ); |
|
| 149 | - if ( $request->has_param( 'limit' ) ) { |
|
| 150 | - $cursor['limit'] = $request->get_param( 'limit' ); |
|
| 148 | + $cursor = $request->get_param('cursor'); |
|
| 149 | + if ($request->has_param('limit')) { |
|
| 150 | + $cursor['limit'] = $request->get_param('limit'); |
|
| 151 | 151 | } |
| 152 | - if ( $request->has_param( 'sort' ) ) { |
|
| 153 | - $cursor['sort'] = $request->get_param( 'sort' ); |
|
| 152 | + if ($request->has_param('sort')) { |
|
| 153 | + $cursor['sort'] = $request->get_param('sort'); |
|
| 154 | 154 | } |
| 155 | - if ( $request->has_param( 'post_types' ) ) { |
|
| 156 | - $cursor['query']['post_types'] = $request->get_param( 'post_types' ); |
|
| 155 | + if ($request->has_param('post_types')) { |
|
| 156 | + $cursor['query']['post_types'] = $request->get_param('post_types'); |
|
| 157 | 157 | } |
| 158 | - if ( $request->has_param( 'has_match' ) ) { |
|
| 159 | - $cursor['query']['has_match'] = $request->get_param( 'has_match' ); |
|
| 158 | + if ($request->has_param('has_match')) { |
|
| 159 | + $cursor['query']['has_match'] = $request->get_param('has_match'); |
|
| 160 | 160 | } |
| 161 | - if ( $request->has_param( 'post_status' ) ) { |
|
| 162 | - $cursor['query']['post_status'] = $request->get_param( 'post_status' ); |
|
| 161 | + if ($request->has_param('post_status')) { |
|
| 162 | + $cursor['query']['post_status'] = $request->get_param('post_status'); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Query. |
| 166 | - $post_types = isset( $cursor['query']['post_types'] ) ? $cursor['query']['post_types'] : apply_filters( |
|
| 166 | + $post_types = isset($cursor['query']['post_types']) ? $cursor['query']['post_types'] : apply_filters( |
|
| 167 | 167 | 'wl_dashboard__post_entity_match__post_types', |
| 168 | 168 | array( |
| 169 | 169 | 'post', |
| 170 | 170 | 'page', |
| 171 | 171 | ) |
| 172 | 172 | ); |
| 173 | - $has_match = isset( $cursor['query']['has_match'] ) ? $cursor['query']['has_match'] : null; |
|
| 173 | + $has_match = isset($cursor['query']['has_match']) ? $cursor['query']['has_match'] : null; |
|
| 174 | 174 | |
| 175 | - $post_status = isset( $cursor['query']['post_status'] ) ? $cursor['query']['post_status'] : null; |
|
| 175 | + $post_status = isset($cursor['query']['post_status']) ? $cursor['query']['post_status'] : null; |
|
| 176 | 176 | |
| 177 | 177 | $items = $this->match_service->list_items( |
| 178 | 178 | array( |
@@ -208,14 +208,14 @@ discard block |
||
| 208 | 208 | * |
| 209 | 209 | * @throws \Exception |
| 210 | 210 | */ |
| 211 | - public function create_post_match( $request ) { |
|
| 212 | - $post_id = $request->get_param( 'post_id' ); |
|
| 211 | + public function create_post_match($request) { |
|
| 212 | + $post_id = $request->get_param('post_id'); |
|
| 213 | 213 | |
| 214 | 214 | // If we dont have a entry on the match table, then add one. |
| 215 | - $content_id = Wordpress_Content_Id::create_post( $post_id ); |
|
| 216 | - if ( ! Wordpress_Content_Service::get_instance()->get_entity_id( $content_id ) ) { |
|
| 217 | - $uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() ); |
|
| 218 | - Wordpress_Content_Service::get_instance()->set_entity_id( $content_id, $uri ); |
|
| 215 | + $content_id = Wordpress_Content_Id::create_post($post_id); |
|
| 216 | + if ( ! Wordpress_Content_Service::get_instance()->get_entity_id($content_id)) { |
|
| 217 | + $uri = Entity_Uri_Generator::create_uri($content_id->get_type(), $content_id->get_id()); |
|
| 218 | + Wordpress_Content_Service::get_instance()->set_entity_id($content_id, $uri); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | $match_id = $this->match_service->get_id( |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @throws \Exception |
| 242 | 242 | */ |
| 243 | - public function update_post_match( $request ) { |
|
| 243 | + public function update_post_match($request) { |
|
| 244 | 244 | |
| 245 | 245 | return $this->match_service->set_jsonld( |
| 246 | - $request->get_param( 'post_id' ), |
|
| 246 | + $request->get_param('post_id'), |
|
| 247 | 247 | Object_Type_Enum::POST, |
| 248 | - $request->get_param( 'match_id' ), |
|
| 248 | + $request->get_param('match_id'), |
|
| 249 | 249 | $request->get_json_params() |
| 250 | 250 | ); |
| 251 | 251 | } |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | public function taxonomy() { |
| 54 | 54 | $taxonomies = $this->params['taxonomies']; |
| 55 | 55 | |
| 56 | - if ( ! isset( $taxonomies ) ) { |
|
| 56 | + if ( ! isset($taxonomies)) { |
|
| 57 | 57 | return $this; |
| 58 | 58 | } |
| 59 | - $sql = Escape::sql_array( $taxonomies ); |
|
| 59 | + $sql = Escape::sql_array($taxonomies); |
|
| 60 | 60 | $this->sql .= " AND tt.taxonomy IN ($sql)"; |
| 61 | 61 | |
| 62 | 62 | return $this; |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | global $wpdb; |
| 67 | 67 | |
| 68 | 68 | // If the ingredient_name_contains value is a non-empty string, add the filter |
| 69 | - if ( is_string( $this->params['ingredient_name_contains'] ) && ! empty( $this->params['ingredient_name_contains'] ) ) { |
|
| 69 | + if (is_string($this->params['ingredient_name_contains']) && ! empty($this->params['ingredient_name_contains'])) { |
|
| 70 | 70 | $ingredient_name_contains = $this->params['ingredient_name_contains']; |
| 71 | - $this->sql .= $wpdb->prepare( ' AND t.name LIKE %s', '%' . $ingredient_name_contains . '%' ); |
|
| 71 | + $this->sql .= $wpdb->prepare(' AND t.name LIKE %s', '%'.$ingredient_name_contains.'%'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | return $this; |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @param $match_service |
| 30 | 30 | */ |
| 31 | - public function __construct( $match_service ) { |
|
| 31 | + public function __construct($match_service) { |
|
| 32 | 32 | $this->match_service = $match_service; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function register_hooks() { |
| 36 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
| 36 | + add_action('rest_api_init', array($this, 'register_routes')); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -46,13 +46,13 @@ discard block |
||
| 46 | 46 | '/term-matches', |
| 47 | 47 | array( |
| 48 | 48 | 'methods' => 'GET', |
| 49 | - 'callback' => array( $this, 'get_term_matches' ), |
|
| 49 | + 'callback' => array($this, 'get_term_matches'), |
|
| 50 | 50 | 'args' => array( |
| 51 | 51 | 'cursor' => array( |
| 52 | 52 | 'type' => 'string', |
| 53 | 53 | 'default' => Cursor::EMPTY_CURSOR_AS_BASE64_STRING, |
| 54 | 54 | 'validate_callback' => 'rest_validate_request_arg', |
| 55 | - 'sanitize_callback' => array( Cursor::class, 'rest_sanitize_request_arg' ), |
|
| 55 | + 'sanitize_callback' => array(Cursor::class, 'rest_sanitize_request_arg'), |
|
| 56 | 56 | ), |
| 57 | 57 | 'limit' => array( |
| 58 | 58 | 'type' => 'integer', |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | 'validate_callback' => 'rest_validate_request_arg', |
| 91 | 91 | ) |
| 92 | 92 | ), |
| 93 | - 'permission_callback' => function () { |
|
| 94 | - return current_user_can( 'manage_options' ); |
|
| 93 | + 'permission_callback' => function() { |
|
| 94 | + return current_user_can('manage_options'); |
|
| 95 | 95 | }, |
| 96 | 96 | ) |
| 97 | 97 | ); |
@@ -102,15 +102,15 @@ discard block |
||
| 102 | 102 | '/term-matches/(?P<term_id>\d+)/matches', |
| 103 | 103 | array( |
| 104 | 104 | 'methods' => 'POST', |
| 105 | - 'callback' => array( $this, 'create_term_match' ), |
|
| 105 | + 'callback' => array($this, 'create_term_match'), |
|
| 106 | 106 | 'args' => array( |
| 107 | 107 | 'term_id' => array( |
| 108 | 108 | 'required' => true, |
| 109 | 109 | 'validate_callback' => 'rest_validate_request_arg', |
| 110 | 110 | ), |
| 111 | 111 | ), |
| 112 | - 'permission_callback' => function () { |
|
| 113 | - return current_user_can( 'manage_options' ); |
|
| 112 | + 'permission_callback' => function() { |
|
| 113 | + return current_user_can('manage_options'); |
|
| 114 | 114 | }, |
| 115 | 115 | ) |
| 116 | 116 | ); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | '/term-matches/(?P<term_id>\d+)/matches/(?P<match_id>\d+)', |
| 122 | 122 | array( |
| 123 | 123 | 'methods' => 'PUT', |
| 124 | - 'callback' => array( $this, 'update_term_match' ), |
|
| 124 | + 'callback' => array($this, 'update_term_match'), |
|
| 125 | 125 | 'args' => array( |
| 126 | 126 | 'term_id' => array( |
| 127 | 127 | 'required' => true, |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | 'validate_callback' => 'rest_validate_request_arg', |
| 133 | 133 | ), |
| 134 | 134 | ), |
| 135 | - 'permission_callback' => function () { |
|
| 136 | - return current_user_can( 'manage_options' ); |
|
| 135 | + 'permission_callback' => function() { |
|
| 136 | + return current_user_can('manage_options'); |
|
| 137 | 137 | }, |
| 138 | 138 | ) |
| 139 | 139 | ); |
@@ -144,27 +144,27 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @var $request \WP_REST_Request |
| 146 | 146 | */ |
| 147 | - public function get_term_matches( $request ) { |
|
| 147 | + public function get_term_matches($request) { |
|
| 148 | 148 | |
| 149 | - $cursor = $request->get_param( 'cursor' ); |
|
| 150 | - if ( $request->has_param( 'limit' ) ) { |
|
| 151 | - $cursor['limit'] = $request->get_param( 'limit' ); |
|
| 149 | + $cursor = $request->get_param('cursor'); |
|
| 150 | + if ($request->has_param('limit')) { |
|
| 151 | + $cursor['limit'] = $request->get_param('limit'); |
|
| 152 | 152 | } |
| 153 | - if ( $request->has_param( 'sort' ) ) { |
|
| 154 | - $cursor['sort'] = $request->get_param( 'sort' ); |
|
| 153 | + if ($request->has_param('sort')) { |
|
| 154 | + $cursor['sort'] = $request->get_param('sort'); |
|
| 155 | 155 | } |
| 156 | - if ( $request->has_param( 'taxonomies' ) ) { |
|
| 157 | - $cursor['query']['taxonomies'] = $request->get_param( 'taxonomies' ); |
|
| 156 | + if ($request->has_param('taxonomies')) { |
|
| 157 | + $cursor['query']['taxonomies'] = $request->get_param('taxonomies'); |
|
| 158 | 158 | } |
| 159 | - if ( $request->has_param( 'has_match' ) ) { |
|
| 160 | - $cursor['query']['has_match'] = $request->get_param( 'has_match' ); |
|
| 159 | + if ($request->has_param('has_match')) { |
|
| 160 | + $cursor['query']['has_match'] = $request->get_param('has_match'); |
|
| 161 | 161 | } |
| 162 | - if ( $request->has_param( 'ingredient_name_contains' ) ) { |
|
| 163 | - $cursor['query']['ingredient_name_contains'] = $request->get_param( 'ingredient_name_contains' ); |
|
| 162 | + if ($request->has_param('ingredient_name_contains')) { |
|
| 163 | + $cursor['query']['ingredient_name_contains'] = $request->get_param('ingredient_name_contains'); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // Query. |
| 167 | - $taxonomies = isset( $cursor['query']['taxonomies'] ) ? $cursor['query']['taxonomies'] : apply_filters( |
|
| 167 | + $taxonomies = isset($cursor['query']['taxonomies']) ? $cursor['query']['taxonomies'] : apply_filters( |
|
| 168 | 168 | 'wl_dashboard__post_entity_match__taxonomies', |
| 169 | 169 | array( |
| 170 | 170 | 'post_tag', |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | ) |
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | - $has_match = isset( $cursor['query']['has_match'] ) ? $cursor['query']['has_match'] : null; |
|
| 176 | - $ingredient_name_contains = isset( $cursor['query']['ingredient_name_contains'] ) ? $cursor['query']['ingredient_name_contains'] : null; |
|
| 175 | + $has_match = isset($cursor['query']['has_match']) ? $cursor['query']['has_match'] : null; |
|
| 176 | + $ingredient_name_contains = isset($cursor['query']['ingredient_name_contains']) ? $cursor['query']['ingredient_name_contains'] : null; |
|
| 177 | 177 | |
| 178 | 178 | $items = $this->match_service->list_items( |
| 179 | 179 | array( |
@@ -209,15 +209,15 @@ discard block |
||
| 209 | 209 | * |
| 210 | 210 | * @throws \Exception |
| 211 | 211 | */ |
| 212 | - public function create_term_match( $request ) { |
|
| 212 | + public function create_term_match($request) { |
|
| 213 | 213 | |
| 214 | - $term_id = $request->get_param( 'term_id' ); |
|
| 214 | + $term_id = $request->get_param('term_id'); |
|
| 215 | 215 | |
| 216 | 216 | // If we dont have a entry on the match table, then add one. |
| 217 | - $content_id = Wordpress_Content_Id::create_term( $term_id ); |
|
| 218 | - if ( ! Wordpress_Content_Service::get_instance()->get_entity_id( $content_id ) ) { |
|
| 219 | - $uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() ); |
|
| 220 | - Wordpress_Content_Service::get_instance()->set_entity_id( $content_id, $uri ); |
|
| 217 | + $content_id = Wordpress_Content_Id::create_term($term_id); |
|
| 218 | + if ( ! Wordpress_Content_Service::get_instance()->get_entity_id($content_id)) { |
|
| 219 | + $uri = Entity_Uri_Generator::create_uri($content_id->get_type(), $content_id->get_id()); |
|
| 220 | + Wordpress_Content_Service::get_instance()->set_entity_id($content_id, $uri); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | $match_id = $this->match_service->get_id( |
@@ -243,12 +243,12 @@ discard block |
||
| 243 | 243 | * |
| 244 | 244 | * @throws \Exception |
| 245 | 245 | */ |
| 246 | - public function update_term_match( $request ) { |
|
| 246 | + public function update_term_match($request) { |
|
| 247 | 247 | |
| 248 | 248 | return $this->match_service->set_jsonld( |
| 249 | - $request->get_param( 'term_id' ), |
|
| 249 | + $request->get_param('term_id'), |
|
| 250 | 250 | Object_Type_Enum::TERM, |
| 251 | - $request->get_param( 'match_id' ), |
|
| 251 | + $request->get_param('match_id'), |
|
| 252 | 252 | $request->get_json_params() |
| 253 | 253 | ); |
| 254 | 254 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @throws \Exception |
| 23 | 23 | */ |
| 24 | - public function list_items( $args ) { |
|
| 24 | + public function list_items($args) { |
|
| 25 | 25 | global $wpdb; |
| 26 | 26 | |
| 27 | 27 | $params = wp_parse_args( |
@@ -42,24 +42,24 @@ discard block |
||
| 42 | 42 | /** |
| 43 | 43 | * @var $sort Sort |
| 44 | 44 | */ |
| 45 | - $sort = new Sort( $params['sort'] ); |
|
| 45 | + $sort = new Sort($params['sort']); |
|
| 46 | 46 | |
| 47 | 47 | $query_builder = new Query_Builder( |
| 48 | 48 | $params, |
| 49 | 49 | $sort |
| 50 | 50 | ); |
| 51 | - $query = $query_builder |
|
| 51 | + $query = $query_builder |
|
| 52 | 52 | ->get(); |
| 53 | 53 | |
| 54 | 54 | $items = $wpdb->get_results( |
| 55 | 55 | // Each function above is preparing `$sql` by using `$wpdb->prepare`. |
| 56 | 56 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 57 | - $wpdb->prepare( $query, Object_Type_Enum::TERM ) |
|
| 57 | + $wpdb->prepare($query, Object_Type_Enum::TERM) |
|
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | - $sort->apply( $items ); |
|
| 60 | + $sort->apply($items); |
|
| 61 | 61 | |
| 62 | - return $this->map( $items ); |
|
| 62 | + return $this->map($items); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -69,12 +69,12 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @return array |
| 71 | 71 | */ |
| 72 | - private function map( array $items ) { |
|
| 72 | + private function map(array $items) { |
|
| 73 | 73 | return array_map( |
| 74 | - function ( $item ) { |
|
| 75 | - $data = json_decode( $item->match_jsonld, true ); |
|
| 76 | - $item->match_name = $data && is_array( $data ) && array_key_exists( 'name', $data ) ? $data['name'] : null; |
|
| 77 | - $item->occurrences = $this->get_term_occurrences( $item->id ); |
|
| 74 | + function($item) { |
|
| 75 | + $data = json_decode($item->match_jsonld, true); |
|
| 76 | + $item->match_name = $data && is_array($data) && array_key_exists('name', $data) ? $data['name'] : null; |
|
| 77 | + $item->occurrences = $this->get_term_occurrences($item->id); |
|
| 78 | 78 | |
| 79 | 79 | return $item; |
| 80 | 80 | }, |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return int |
| 91 | 91 | */ |
| 92 | - private function get_term_occurrences( $term_id ) { |
|
| 93 | - $term = get_term( $term_id ); |
|
| 92 | + private function get_term_occurrences($term_id) { |
|
| 93 | + $term = get_term($term_id); |
|
| 94 | 94 | |
| 95 | - if ( ! is_wp_error( $term ) ) { |
|
| 95 | + if ( ! is_wp_error($term)) { |
|
| 96 | 96 | return $term->count; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -17,14 +17,14 @@ |
||
| 17 | 17 | * @return string |
| 18 | 18 | */ |
| 19 | 19 | public function get_field_name() { |
| 20 | - $tmp_sort_field_name = substr( $this->sort, 1 ); |
|
| 21 | - if ( 'id' === $tmp_sort_field_name ) { |
|
| 20 | + $tmp_sort_field_name = substr($this->sort, 1); |
|
| 21 | + if ('id' === $tmp_sort_field_name) { |
|
| 22 | 22 | return 't.term_id'; |
| 23 | - } elseif ( 'ingredient_term' === $tmp_sort_field_name ) { |
|
| 23 | + } elseif ('ingredient_term' === $tmp_sort_field_name) { |
|
| 24 | 24 | return 't.name'; |
| 25 | - } elseif ( 'matched_ingredient' === $tmp_sort_field_name ) { |
|
| 25 | + } elseif ('matched_ingredient' === $tmp_sort_field_name) { |
|
| 26 | 26 | return 't.match_name'; |
| 27 | - } elseif ( 'occurrences' === $tmp_sort_field_name ) { |
|
| 27 | + } elseif ('occurrences' === $tmp_sort_field_name) { |
|
| 28 | 28 | // @todo |
| 29 | 29 | } |
| 30 | 30 | |