@@ -129,7 +129,7 @@ |
||
| 129 | 129 | * |
| 130 | 130 | * @param string $route |
| 131 | 131 | * @param string $regex |
| 132 | - * @param array $match_keys EXCLUDING matching the entire regex |
|
| 132 | + * @param string[] $match_keys EXCLUDING matching the entire regex |
|
| 133 | 133 | * @return array where $match_keys are the keys (the first value of $match_keys |
| 134 | 134 | * becomes the first key of the return value, etc. Eg passing in $match_keys of |
| 135 | 135 | * array( 'model', 'id' ), will, if the regex is successful, will return |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\libraries\rest_api\controllers; |
| 3 | 3 | |
| 4 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 5 | - exit( 'No direct script access allowed' ); |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | protected $_requested_version; |
| 37 | 37 | |
| 38 | 38 | public function __construct() { |
| 39 | - $this->_debug_mode = defined( 'EE_REST_API_DEBUG_MODE' ) ? EE_REST_API_DEBUG_MODE : false; |
|
| 39 | + $this->_debug_mode = defined('EE_REST_API_DEBUG_MODE') ? EE_REST_API_DEBUG_MODE : false; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * Sets the version the user requested |
| 45 | 45 | * @param string $version eg '4.8' |
| 46 | 46 | */ |
| 47 | - public function set_requested_version( $version ) { |
|
| 47 | + public function set_requested_version($version) { |
|
| 48 | 48 | $this->_requested_version = $version; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @param string $key |
| 54 | 54 | * @param string|array $info |
| 55 | 55 | */ |
| 56 | - protected function _set_debug_info( $key, $info ){ |
|
| 57 | - $this->_debug_info[ $key ] = $info; |
|
| 56 | + protected function _set_debug_info($key, $info) { |
|
| 57 | + $this->_debug_info[$key] = $info; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -69,52 +69,52 @@ discard block |
||
| 69 | 69 | * @param array|\WP_Error|\Exception $response |
| 70 | 70 | * @return \WP_REST_Response |
| 71 | 71 | */ |
| 72 | - public function send_response( $response ) { |
|
| 73 | - if( $response instanceof \Exception ) { |
|
| 74 | - $response = new \WP_Error( $response->getCode(), $response->getMessage() ); |
|
| 72 | + public function send_response($response) { |
|
| 73 | + if ($response instanceof \Exception) { |
|
| 74 | + $response = new \WP_Error($response->getCode(), $response->getMessage()); |
|
| 75 | 75 | } |
| 76 | - if( $response instanceof \WP_Error ) { |
|
| 76 | + if ($response instanceof \WP_Error) { |
|
| 77 | 77 | //we want to send a "normal"-looking WP error response, but we also |
| 78 | 78 | //want to add headers. It doesn't seem WP API 1.2 supports this. |
| 79 | 79 | //I'd like to use WP_JSON_Server::error_to_response() but its protected |
| 80 | 80 | //so here's most of it copy-and-pasted :P |
| 81 | 81 | $error_data = $response->get_error_data(); |
| 82 | - if ( is_array( $error_data ) && isset( $error_data['status'] ) ) { |
|
| 82 | + if (is_array($error_data) && isset($error_data['status'])) { |
|
| 83 | 83 | $status = $error_data['status']; |
| 84 | 84 | } else { |
| 85 | 85 | $status = 500; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $errors = array(); |
| 89 | - foreach ( (array) $response->errors as $code => $messages ) { |
|
| 90 | - foreach ( (array) $messages as $message ) { |
|
| 89 | + foreach ((array) $response->errors as $code => $messages) { |
|
| 90 | + foreach ((array) $messages as $message) { |
|
| 91 | 91 | $errors[] = array( |
| 92 | 92 | 'code' => $code, |
| 93 | 93 | 'message' => $message, |
| 94 | - 'data' => $response->get_error_data( $code ) |
|
| 94 | + 'data' => $response->get_error_data($code) |
|
| 95 | 95 | ); |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | - $data = isset( $errors[0] ) ? $errors[0] : array(); |
|
| 99 | - if ( count( $errors ) > 1 ) { |
|
| 98 | + $data = isset($errors[0]) ? $errors[0] : array(); |
|
| 99 | + if (count($errors) > 1) { |
|
| 100 | 100 | // Remove the primary error. |
| 101 | - array_shift( $errors ); |
|
| 101 | + array_shift($errors); |
|
| 102 | 102 | $data['additional_errors'] = $errors; |
| 103 | 103 | } |
| 104 | - $rest_response = new \WP_REST_Response( $data, $status ); |
|
| 105 | - }else{ |
|
| 106 | - $rest_response = new \WP_REST_Response( $response, 200 ); |
|
| 104 | + $rest_response = new \WP_REST_Response($data, $status); |
|
| 105 | + } else { |
|
| 106 | + $rest_response = new \WP_REST_Response($response, 200); |
|
| 107 | 107 | } |
| 108 | 108 | $headers = array(); |
| 109 | - if( $this->_debug_mode && is_array( $this->_debug_info ) ) { |
|
| 110 | - foreach( $this->_debug_info as $debug_key => $debug_info ) { |
|
| 111 | - if( is_array( $debug_info ) ) { |
|
| 112 | - $debug_info = json_encode( $debug_info ); |
|
| 109 | + if ($this->_debug_mode && is_array($this->_debug_info)) { |
|
| 110 | + foreach ($this->_debug_info as $debug_key => $debug_info) { |
|
| 111 | + if (is_array($debug_info)) { |
|
| 112 | + $debug_info = json_encode($debug_info); |
|
| 113 | 113 | } |
| 114 | - $headers[ 'X-EE4-Debug-' . ucwords( $debug_key ) ] = $debug_info; |
|
| 114 | + $headers['X-EE4-Debug-'.ucwords($debug_key)] = $debug_info; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | - $rest_response->set_headers( $headers ); |
|
| 117 | + $rest_response->set_headers($headers); |
|
| 118 | 118 | return $rest_response; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -136,23 +136,23 @@ discard block |
||
| 136 | 136 | * array( 'model' => 'foo', 'id' => 'bar' ) |
| 137 | 137 | * @throws \EE_Error if it couldn't be parsed |
| 138 | 138 | */ |
| 139 | - public function parse_route( $route, $regex, $match_keys ) { |
|
| 139 | + public function parse_route($route, $regex, $match_keys) { |
|
| 140 | 140 | $indexed_matches = array(); |
| 141 | - $success = preg_match( $regex, $route, $matches ); |
|
| 142 | - if( |
|
| 143 | - is_array( $matches ) ) { |
|
| 141 | + $success = preg_match($regex, $route, $matches); |
|
| 142 | + if ( |
|
| 143 | + is_array($matches) ) { |
|
| 144 | 144 | //skip the overall regex match. Who cares |
| 145 | - for( $i = 1; $i <= count( $match_keys ); $i++ ) { |
|
| 146 | - if( ! isset( $matches[ $i ] ) ) { |
|
| 145 | + for ($i = 1; $i <= count($match_keys); $i++) { |
|
| 146 | + if ( ! isset($matches[$i])) { |
|
| 147 | 147 | $success = false; |
| 148 | 148 | } else { |
| 149 | - $indexed_matches[ $match_keys[ $i - 1 ] ] = $matches[ $i ]; |
|
| 149 | + $indexed_matches[$match_keys[$i - 1]] = $matches[$i]; |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | - if( ! $success ) { |
|
| 153 | + if ( ! $success) { |
|
| 154 | 154 | throw new \EE_Error( |
| 155 | - __( 'We could not parse the URL. Please contact Event Espresso Support', 'event_espresso' ), |
|
| 155 | + __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'), |
|
| 156 | 156 | 'endpoint_parsing_error' |
| 157 | 157 | ); |
| 158 | 158 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
| 3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 4 | - exit( 'No direct script access allowed' ); |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -21,16 +21,16 @@ discard block |
||
| 21 | 21 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
| 22 | 22 | * @return boolean |
| 23 | 23 | */ |
| 24 | - public static function current_user_has_partial_access_to( $model, $model_context = \EEM_Base::caps_read ) { |
|
| 25 | - if( apply_filters( 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', false, $model, $model ) ) { |
|
| 24 | + public static function current_user_has_partial_access_to($model, $model_context = \EEM_Base::caps_read) { |
|
| 25 | + if (apply_filters('FHEE__Capabilities__current_user_has_partial_access_to__override_begin', false, $model, $model)) { |
|
| 26 | 26 | return true; |
| 27 | 27 | } |
| 28 | - foreach( $model->caps_missing( $model_context ) as $capability_name => $restriction_obj ) { |
|
| 29 | - if( $restriction_obj instanceof \EE_Return_None_Where_Conditions ){ |
|
| 28 | + foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) { |
|
| 29 | + if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) { |
|
| 30 | 30 | return false; |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | - if( apply_filters( 'FHEE__Capabilities__current_user_has_partial_access_to__override_end', false, $model, $model ) ) { |
|
| 33 | + if (apply_filters('FHEE__Capabilities__current_user_has_partial_access_to__override_end', false, $model, $model)) { |
|
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | return true; |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @param string $request_type one of the constants on WP_JSON_Server |
| 44 | 44 | * @return array |
| 45 | 45 | */ |
| 46 | - public static function get_missing_permissions( $model, $request_type = \EEM_Base::caps_read ) { |
|
| 47 | - return $model->caps_missing( $request_type ); |
|
| 46 | + public static function get_missing_permissions($model, $request_type = \EEM_Base::caps_read) { |
|
| 47 | + return $model->caps_missing($request_type); |
|
| 48 | 48 | } |
| 49 | 49 | /** |
| 50 | 50 | * Gets a string of all the capabilities the current user is missing that affected |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
| 55 | 55 | * @return string |
| 56 | 56 | */ |
| 57 | - public static function get_missing_permissions_string( $model, $model_context = \EEM_Base::caps_read ) { |
|
| 58 | - return implode(',', array_keys( self::get_missing_permissions( $model, $model_context ) ) ); |
|
| 57 | + public static function get_missing_permissions_string($model, $model_context = \EEM_Base::caps_read) { |
|
| 58 | + return implode(',', array_keys(self::get_missing_permissions($model, $model_context))); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -66,25 +66,25 @@ discard block |
||
| 66 | 66 | * @param Model_Version_Info $model_version_info |
| 67 | 67 | * @return array ready for converting into json |
| 68 | 68 | */ |
| 69 | - public static function filter_out_inaccessible_entity_fields( $entity, $model, $request_type, $model_version_info ) { |
|
| 69 | + public static function filter_out_inaccessible_entity_fields($entity, $model, $request_type, $model_version_info) { |
|
| 70 | 70 | //we only care to do this for frontend reads and when the user can't edit the item |
| 71 | - if( $request_type !== \EEM_Base::caps_read || |
|
| 72 | - $model->exists( array( |
|
| 73 | - array( $model->primary_key_name() => $entity[ $model->primary_key_name() ] ), |
|
| 71 | + if ($request_type !== \EEM_Base::caps_read || |
|
| 72 | + $model->exists(array( |
|
| 73 | + array($model->primary_key_name() => $entity[$model->primary_key_name()]), |
|
| 74 | 74 | 'default_where_conditions' => 'none', |
| 75 | - 'caps' => \EEM_Base::caps_edit ) ) ) { |
|
| 75 | + 'caps' => \EEM_Base::caps_edit ))) { |
|
| 76 | 76 | return $entity; |
| 77 | 77 | } |
| 78 | - foreach( $model->field_settings() as $field_name => $field_obj ){ |
|
| 79 | - if( $model_version_info->field_has_rendered_format( $field_obj ) |
|
| 80 | - && isset( $entity[ $field_name ][ 'raw' ] ) |
|
| 78 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
| 79 | + if ($model_version_info->field_has_rendered_format($field_obj) |
|
| 80 | + && isset($entity[$field_name]['raw']) |
|
| 81 | 81 | ) { |
| 82 | - unset( $entity[ $field_name ][ 'raw' ] ); |
|
| 82 | + unset($entity[$field_name]['raw']); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | //theoretically we may want to filter out specific fields for specific models |
| 86 | 86 | |
| 87 | - return apply_filters( 'FHEE__Capabilities__filter_out_inaccessible_entity_fields', $entity, $model, $request_type ); |
|
| 87 | + return apply_filters('FHEE__Capabilities__filter_out_inaccessible_entity_fields', $entity, $model, $request_type); |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\libraries\rest_api\controllers\config; |
| 3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 4 | - exit( 'No direct script access allowed' ); |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | * @param \WP_REST_Request $request |
| 22 | 22 | * @return \EE_Config|\WP_Error |
| 23 | 23 | */ |
| 24 | - public static function handle_request( \WP_REST_Request $request) { |
|
| 24 | + public static function handle_request(\WP_REST_Request $request) { |
|
| 25 | 25 | $cap = \EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
| 26 | - if( \EE_Capabilities::instance()->current_user_can( $cap, 'read_over_api' ) ){ |
|
| 26 | + if (\EE_Capabilities::instance()->current_user_can($cap, 'read_over_api')) { |
|
| 27 | 27 | return \EE_Config::instance(); |
| 28 | - }else{ |
|
| 28 | + } else { |
|
| 29 | 29 | return new \WP_Error( |
| 30 | 30 | 'cannot_read_config', |
| 31 | 31 | sprintf( |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | ), |
| 36 | 36 | $cap |
| 37 | 37 | ), |
| 38 | - array( 'status' => 403 ) |
|
| 38 | + array('status' => 403) |
|
| 39 | 39 | ); |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -293,7 +293,7 @@ |
||
| 293 | 293 | //if it's not above the current core version, and it's compatible with the current version of core |
| 294 | 294 | if( $possibly_served_version < EED_REST_API::core_version() && $possibly_served_version >= $lowest_compatible_version ) { |
| 295 | 295 | $versions_served[ $possibly_served_version ] = true; |
| 296 | - }else { |
|
| 296 | + } else { |
|
| 297 | 297 | $versions_served[ $possibly_served_version ] = false; |
| 298 | 298 | } |
| 299 | 299 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @return EED_Core_Rest_Api |
| 23 | 23 | */ |
| 24 | 24 | public static function instance() { |
| 25 | - return parent::get_instance( __CLASS__ ); |
|
| 25 | + return parent::get_instance(__CLASS__); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | |
| 54 | 54 | public static function set_hooks_both() { |
| 55 | - add_action( 'rest_api_init', array( 'EED_Core_REST_API', 'register_routes' ) ); |
|
| 56 | - add_filter( 'rest_route_data', array( 'EED_Core_REST_API', 'hide_old_endpoints' ), 10, 2 ); |
|
| 57 | - add_filter( 'rest_index', array( 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index' ) ); |
|
| 55 | + add_action('rest_api_init', array('EED_Core_REST_API', 'register_routes')); |
|
| 56 | + add_filter('rest_route_data', array('EED_Core_REST_API', 'hide_old_endpoints'), 10, 2); |
|
| 57 | + add_filter('rest_index', array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index')); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -63,16 +63,16 @@ discard block |
||
| 63 | 63 | * so we actually prefer to only do it when an EE plugin is activated or upgraded |
| 64 | 64 | */ |
| 65 | 65 | public static function register_routes() { |
| 66 | - foreach( EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls ) { |
|
| 67 | - foreach( $relative_urls as $endpoint => $routes ) { |
|
| 68 | - foreach( $routes as $route ) { |
|
| 66 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 67 | + foreach ($relative_urls as $endpoint => $routes) { |
|
| 68 | + foreach ($routes as $route) { |
|
| 69 | 69 | register_rest_route( |
| 70 | 70 | $namespace, |
| 71 | 71 | $endpoint, |
| 72 | 72 | array( |
| 73 | - 'callback' => $route[ 'callback' ], |
|
| 74 | - 'methods' => $route[ 'methods' ], |
|
| 75 | - 'args' => isset( $route[ 'args' ] ) ? $route[ 'args' ] : array(), |
|
| 73 | + 'callback' => $route['callback'], |
|
| 74 | + 'methods' => $route['methods'], |
|
| 75 | + 'args' => isset($route['args']) ? $route['args'] : array(), |
|
| 76 | 76 | ) |
| 77 | 77 | ); |
| 78 | 78 | } |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | * } |
| 90 | 90 | */ |
| 91 | 91 | public static function get_ee_route_data() { |
| 92 | - $ee_routes = get_option( self::saved_routes_option_names, null ); |
|
| 93 | - if( ! $ee_routes || ( defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE )){ |
|
| 92 | + $ee_routes = get_option(self::saved_routes_option_names, null); |
|
| 93 | + if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
| 94 | 94 | self::save_ee_routes(); |
| 95 | - $ee_routes = get_option( self::saved_routes_option_names, array() ); |
|
| 95 | + $ee_routes = get_option(self::saved_routes_option_names, array()); |
|
| 96 | 96 | } |
| 97 | 97 | return $ee_routes; |
| 98 | 98 | } |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | * @return void |
| 104 | 104 | */ |
| 105 | 105 | public static function save_ee_routes() { |
| 106 | - if( EE_Maintenance_Mode::instance()->models_can_query() ){ |
|
| 106 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 107 | 107 | $instance = self::instance(); |
| 108 | 108 | $routes = array_replace_recursive( |
| 109 | 109 | $instance->_register_config_routes(), |
| 110 | 110 | $instance->_register_meta_routes(), |
| 111 | 111 | $instance->_register_model_routes() |
| 112 | 112 | ); |
| 113 | - update_option( self::saved_routes_option_names, $routes, true ); |
|
| 113 | + update_option(self::saved_routes_option_names, $routes, true); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @return array @see get_ee_route_data |
| 120 | 120 | */ |
| 121 | 121 | protected function _register_model_routes() { |
| 122 | - EE_Registry::instance()->load_helper( 'Inflector' ); |
|
| 122 | + EE_Registry::instance()->load_helper('Inflector'); |
|
| 123 | 123 | $models_to_register = apply_filters( |
| 124 | 124 | 'FHEE__EED_Core_REST_API___register_model_routes', |
| 125 | 125 | EE_Registry::instance()->non_abstract_db_models |
@@ -128,23 +128,23 @@ discard block |
||
| 128 | 128 | unset($models_to_register['Extra_Meta']); |
| 129 | 129 | unset($models_to_register['Extra_Join']); |
| 130 | 130 | $model_routes = array( ); |
| 131 | - foreach( self::versions_served() as $version => $hidden_endpoint ) { |
|
| 131 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 132 | 132 | |
| 133 | - foreach ( $models_to_register as $model_name => $model_classname ) { |
|
| 133 | + foreach ($models_to_register as $model_name => $model_classname) { |
|
| 134 | 134 | //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
| 135 | - $ee_namespace = self::ee_api_namespace . $version; |
|
| 136 | - $plural_model_route = EEH_Inflector::pluralize_and_lower( $model_name ); |
|
| 137 | - $singular_model_route = $plural_model_route . '/(?P<id>\d+)' ; |
|
| 138 | - $model_routes[ $ee_namespace ][ $plural_model_route ] = array( |
|
| 135 | + $ee_namespace = self::ee_api_namespace.$version; |
|
| 136 | + $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name); |
|
| 137 | + $singular_model_route = $plural_model_route.'/(?P<id>\d+)'; |
|
| 138 | + $model_routes[$ee_namespace][$plural_model_route] = array( |
|
| 139 | 139 | array( |
| 140 | 140 | 'callback' => array( |
| 141 | 141 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
| 142 | 142 | 'handle_request_get_all' ), |
| 143 | 143 | 'methods' => WP_REST_Server::READABLE, |
| 144 | 144 | 'hidden_endpoint' => $hidden_endpoint, |
| 145 | - 'args' => $this->_get_read_query_params( $model_name ), |
|
| 145 | + 'args' => $this->_get_read_query_params($model_name), |
|
| 146 | 146 | '_links' => array( |
| 147 | - 'self' => rest_url( $ee_namespace . $singular_model_route ), |
|
| 147 | + 'self' => rest_url($ee_namespace.$singular_model_route), |
|
| 148 | 148 | ) |
| 149 | 149 | ), |
| 150 | 150 | // array( |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | // 'hidden_endpoint' => $hidden_endpoint |
| 156 | 156 | // ) |
| 157 | 157 | ); |
| 158 | - $model_routes[ $ee_namespace ][ $singular_model_route ] = array( |
|
| 158 | + $model_routes[$ee_namespace][$singular_model_route] = array( |
|
| 159 | 159 | array( |
| 160 | 160 | 'callback' => array( |
| 161 | 161 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | 'include' => array( |
| 167 | 167 | 'required' => false, |
| 168 | 168 | 'default' => '*', |
| 169 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#Including_Specific_Fields_and_Related_Entities_in_Results for documentation', 'event_espresso' ), |
|
| 169 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#Including_Specific_Fields_and_Related_Entities_in_Results for documentation', 'event_espresso'), |
|
| 170 | 170 | ), |
| 171 | 171 | ) |
| 172 | 172 | ), |
@@ -179,20 +179,20 @@ discard block |
||
| 179 | 179 | // ), |
| 180 | 180 | ); |
| 181 | 181 | //@todo: also handle DELETE for a single item |
| 182 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
| 183 | - foreach ( $model->relation_settings() as $relation_name => $relation_obj ) { |
|
| 182 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
| 183 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 184 | 184 | $related_model_name_endpoint_part = EventEspresso\core\libraries\rest_api\controllers\model\Read::get_related_entity_name( |
| 185 | 185 | $relation_name, |
| 186 | 186 | $relation_obj |
| 187 | 187 | ); |
| 188 | - $model_routes[ $ee_namespace ][ $singular_model_route . '/' . $related_model_name_endpoint_part ] = array( |
|
| 188 | + $model_routes[$ee_namespace][$singular_model_route.'/'.$related_model_name_endpoint_part] = array( |
|
| 189 | 189 | array( |
| 190 | 190 | 'callback' => array( |
| 191 | 191 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
| 192 | 192 | 'handle_request_get_related' ), |
| 193 | 193 | 'methods' => WP_REST_Server::READABLE, |
| 194 | 194 | 'hidden_endpoint' => $hidden_endpoint, |
| 195 | - 'args' => $this->_get_read_query_params( $relation_name ), |
|
| 195 | + 'args' => $this->_get_read_query_params($relation_name), |
|
| 196 | 196 | ), |
| 197 | 197 | // array( |
| 198 | 198 | // 'callback' => array( |
@@ -215,47 +215,47 @@ discard block |
||
| 215 | 215 | * @param string $model_name eg 'Event' or 'Venue' |
| 216 | 216 | * @return array describing the args acceptable when querying this model |
| 217 | 217 | */ |
| 218 | - protected function _get_read_query_params( $model_name ) { |
|
| 219 | - $model = EE_Registry::instance()->load_model( $model_name ); |
|
| 218 | + protected function _get_read_query_params($model_name) { |
|
| 219 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 220 | 220 | $default_orderby = array(); |
| 221 | - foreach( $model->get_combined_primary_key_fields() as $key_field ) { |
|
| 222 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
| 221 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 222 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
| 223 | 223 | } |
| 224 | 224 | return array( |
| 225 | 225 | 'where' => array( |
| 226 | 226 | 'required' => false, |
| 227 | 227 | 'default' => array(), |
| 228 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#where for documentation', 'event_espresso' ), |
|
| 228 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#where for documentation', 'event_espresso'), |
|
| 229 | 229 | ), |
| 230 | 230 | 'limit' => array( |
| 231 | 231 | 'required' => false, |
| 232 | 232 | 'default' => 50, |
| 233 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#limit for documentation', 'event_espresso' ) |
|
| 233 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#limit for documentation', 'event_espresso') |
|
| 234 | 234 | ), |
| 235 | 235 | 'order_by' => array( |
| 236 | 236 | 'required' => false, |
| 237 | 237 | 'default' => $default_orderby, |
| 238 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#order_by for documentation', 'event_espresso' ) |
|
| 238 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#order_by for documentation', 'event_espresso') |
|
| 239 | 239 | ), |
| 240 | 240 | 'group_by' => array( |
| 241 | 241 | 'required' => false, |
| 242 | 242 | 'default' => null, |
| 243 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#group_by for documentation', 'event_espresso' ) |
|
| 243 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#group_by for documentation', 'event_espresso') |
|
| 244 | 244 | ), |
| 245 | 245 | 'having' => array( |
| 246 | 246 | 'required' => false, |
| 247 | 247 | 'default' => null, |
| 248 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#having for documentation', 'event_espresso' ) |
|
| 248 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#having for documentation', 'event_espresso') |
|
| 249 | 249 | ), |
| 250 | 250 | 'caps' => array( |
| 251 | 251 | 'required' => false, |
| 252 | 252 | 'default' => EEM_Base::caps_read, |
| 253 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#caps for documentation', 'event_espresso' ) |
|
| 253 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#caps for documentation', 'event_espresso') |
|
| 254 | 254 | ), |
| 255 | 255 | 'include' => array( |
| 256 | 256 | 'required' => false, |
| 257 | 257 | 'default' => '*', |
| 258 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#Including_Specific_Fields_and_Related_Entities_in_Results for documentation', 'event_espresso' ), |
|
| 258 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#Including_Specific_Fields_and_Related_Entities_in_Results for documentation', 'event_espresso'), |
|
| 259 | 259 | ), |
| 260 | 260 | ); |
| 261 | 261 | } |
@@ -266,8 +266,8 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | protected function _register_config_routes() { |
| 268 | 268 | $config_routes = array(); |
| 269 | - foreach( self::versions_served() as $version => $hidden_endpoint ) { |
|
| 270 | - $config_routes[ self::ee_api_namespace . $version ][ 'config' ] = array( |
|
| 269 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 270 | + $config_routes[self::ee_api_namespace.$version]['config'] = array( |
|
| 271 | 271 | array( |
| 272 | 272 | 'callback' => array( |
| 273 | 273 | 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | protected function _register_meta_routes() { |
| 288 | 288 | $meta_routes = array(); |
| 289 | - foreach( self::versions_served() as $version => $hidden_endpoint ) { |
|
| 290 | - $meta_routes[ self::ee_api_namespace . $version ][ '/resources' ] = array( |
|
| 289 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 290 | + $meta_routes[self::ee_api_namespace.$version]['/resources'] = array( |
|
| 291 | 291 | array( |
| 292 | 292 | 'callback' => array( |
| 293 | 293 | 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
@@ -308,13 +308,13 @@ discard block |
||
| 308 | 308 | * @param array $route_data |
| 309 | 309 | * @return array |
| 310 | 310 | */ |
| 311 | - public function hide_old_endpoints( $route_data ) { |
|
| 312 | - foreach( EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls ) { |
|
| 313 | - foreach( $relative_urls as $endpoint => $routes ) { |
|
| 314 | - foreach( $routes as $route ) { |
|
| 315 | - if( $route[ 'hidden_endpoint' ] ) { |
|
| 316 | - $full_route = '/' . ltrim( $namespace, '/' ) . '/' . ltrim( $endpoint, '/' ); |
|
| 317 | - unset( $route_data[ $full_route ] ); |
|
| 311 | + public function hide_old_endpoints($route_data) { |
|
| 312 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 313 | + foreach ($relative_urls as $endpoint => $routes) { |
|
| 314 | + foreach ($routes as $route) { |
|
| 315 | + if ($route['hidden_endpoint']) { |
|
| 316 | + $full_route = '/'.ltrim($namespace, '/').'/'.ltrim($endpoint, '/'); |
|
| 317 | + unset($route_data[$full_route]); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | } |
@@ -354,17 +354,17 @@ discard block |
||
| 354 | 354 | public static function versions_served() { |
| 355 | 355 | $version_compatibilities = EED_Core_Rest_Api::version_compatibilities(); |
| 356 | 356 | $versions_served = array(); |
| 357 | - $lowest_compatible_version = $version_compatibilities[ EED_Core_Rest_Api::core_version() ]; |
|
| 357 | + $lowest_compatible_version = $version_compatibilities[EED_Core_Rest_Api::core_version()]; |
|
| 358 | 358 | //for each version of core we have ever served: |
| 359 | - foreach( array_keys( EED_Core_Rest_Api::version_compatibilities() ) as $possibly_served_version ) { |
|
| 359 | + foreach (array_keys(EED_Core_Rest_Api::version_compatibilities()) as $possibly_served_version) { |
|
| 360 | 360 | //if it's not above the current core version, and it's compatible with the current version of core |
| 361 | - if( |
|
| 361 | + if ( |
|
| 362 | 362 | $possibly_served_version < EED_Core_Rest_Api::core_version() |
| 363 | 363 | && $possibly_served_version >= $lowest_compatible_version |
| 364 | 364 | ) { |
| 365 | - $versions_served[ $possibly_served_version ] = true; |
|
| 366 | - }else { |
|
| 367 | - $versions_served[ $possibly_served_version ] = false; |
|
| 365 | + $versions_served[$possibly_served_version] = true; |
|
| 366 | + } else { |
|
| 367 | + $versions_served[$possibly_served_version] = false; |
|
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | return $versions_served; |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | * @return string |
| 378 | 378 | */ |
| 379 | 379 | public static function core_version() { |
| 380 | - return apply_filters( 'FHEE__EED_Core_REST_API__core_version', implode('.', array_slice( explode( '.', espresso_version() ), 0, 3 ) ) ); |
|
| 380 | + return apply_filters('FHEE__EED_Core_REST_API__core_version', implode('.', array_slice(explode('.', espresso_version()), 0, 3))); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * @param WP $WP |
| 390 | 390 | * @return void |
| 391 | 391 | */ |
| 392 | - public function run( $WP ) { |
|
| 392 | + public function run($WP) { |
|
| 393 | 393 | |
| 394 | 394 | } |
| 395 | 395 | |
@@ -653,6 +653,10 @@ |
||
| 653 | 653 | } |
| 654 | 654 | return $model_ready_query_params; |
| 655 | 655 | } |
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * @param \EEM_Base $model |
|
| 659 | + */ |
|
| 656 | 660 | public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
| 657 | 661 | $model_ready_query_params = array(); |
| 658 | 662 | foreach( $query_params as $key => $value ) { |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | ){ |
| 228 | 228 | if( $relation instanceof \EE_Belongs_To_Relation ) { |
| 229 | 229 | $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
| 230 | - }else{ |
|
| 230 | + } else{ |
|
| 231 | 231 | $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
| 232 | 232 | } |
| 233 | 233 | return new \WP_Error( |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | } |
| 281 | 281 | if( $relation instanceof \EE_Belongs_To_Relation ){ |
| 282 | 282 | return array_shift( $nice_results ); |
| 283 | - }else{ |
|
| 283 | + } else{ |
|
| 284 | 284 | return $nice_results; |
| 285 | 285 | } |
| 286 | 286 | } |
@@ -331,26 +331,26 @@ discard block |
||
| 331 | 331 | $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
| 332 | 332 | if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
| 333 | 333 | unset( $result[ $field_name ] ); |
| 334 | - }elseif( |
|
| 334 | + } elseif( |
|
| 335 | 335 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
| 336 | 336 | ){ |
| 337 | 337 | $result[ $field_name ] = array( |
| 338 | 338 | 'raw' => $field_obj->prepare_for_get( $field_value ), |
| 339 | 339 | 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
| 340 | 340 | ); |
| 341 | - }elseif( |
|
| 341 | + } elseif( |
|
| 342 | 342 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
| 343 | 343 | ){ |
| 344 | 344 | $result[ $field_name ] = array( |
| 345 | 345 | 'raw' => $field_obj->prepare_for_get( $field_value ), |
| 346 | 346 | 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
| 347 | 347 | ); |
| 348 | - }elseif( $field_obj instanceof \EE_Datetime_Field ){ |
|
| 348 | + } elseif( $field_obj instanceof \EE_Datetime_Field ){ |
|
| 349 | 349 | if( $raw_field_value instanceof \DateTime ) { |
| 350 | 350 | $raw_field_value = $raw_field_value->format( 'c' ); |
| 351 | 351 | } |
| 352 | 352 | $result[ $field_name ] = mysql_to_rfc3339( $raw_field_value ); |
| 353 | - }else{ |
|
| 353 | + } else{ |
|
| 354 | 354 | $value_prepared = $field_obj->prepare_for_get( $field_value ); |
| 355 | 355 | |
| 356 | 356 | $result[ $field_name ] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared; |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | public static function get_related_entity_name( $relation_name, $relation_obj ){ |
| 480 | 480 | if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
| 481 | 481 | return strtolower( $relation_name ); |
| 482 | - }else{ |
|
| 482 | + } else{ |
|
| 483 | 483 | return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
| 484 | 484 | } |
| 485 | 485 | } |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
| 549 | 549 | if( in_array( $context, $valid_contexts ) ){ |
| 550 | 550 | return $context; |
| 551 | - }else{ |
|
| 551 | + } else{ |
|
| 552 | 552 | return \EEM_Base::caps_read; |
| 553 | 553 | } |
| 554 | 554 | } |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | $order_by = $query_parameters[ 'order_by' ]; |
| 574 | 574 | } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
| 575 | 575 | $order_by = $query_parameters[ 'orderby' ]; |
| 576 | - }else{ |
|
| 576 | + } else{ |
|
| 577 | 577 | $order_by = null; |
| 578 | 578 | } |
| 579 | 579 | if( $order_by !== null ){ |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | $group_by = $query_parameters[ 'group_by' ]; |
| 584 | 584 | } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
| 585 | 585 | $group_by = $query_parameters[ 'groupby' ]; |
| 586 | - }else{ |
|
| 586 | + } else{ |
|
| 587 | 587 | $group_by = null; |
| 588 | 588 | } |
| 589 | 589 | if( $group_by !== null ){ |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
| 607 | 607 | if( is_string( $query_parameters[ 'limit' ] ) ) { |
| 608 | 608 | $limit_array = explode(',', $query_parameters['limit']); |
| 609 | - }else { |
|
| 609 | + } else { |
|
| 610 | 610 | $limit_array = $query_parameters[ 'limit' ]; |
| 611 | 611 | } |
| 612 | 612 | $sanitized_limit = array(); |
@@ -622,12 +622,12 @@ discard block |
||
| 622 | 622 | $sanitized_limit[] = intval( $limit_part ); |
| 623 | 623 | } |
| 624 | 624 | $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
| 625 | - }else{ |
|
| 625 | + } else{ |
|
| 626 | 626 | $model_query_params[ 'limit' ] = 50; |
| 627 | 627 | } |
| 628 | 628 | if( isset( $query_parameters[ 'caps' ] ) ) { |
| 629 | 629 | $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
| 630 | - }else{ |
|
| 630 | + } else{ |
|
| 631 | 631 | $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
| 632 | 632 | } |
| 633 | 633 | return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | foreach( $query_params as $key => $value ) { |
| 648 | 648 | if( is_array( $value ) ) { |
| 649 | 649 | $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
| 650 | - }else{ |
|
| 650 | + } else{ |
|
| 651 | 651 | $model_ready_query_params[ $key ] = $value; |
| 652 | 652 | } |
| 653 | 653 | } |
@@ -689,11 +689,11 @@ discard block |
||
| 689 | 689 | //found the model name at the exact start |
| 690 | 690 | $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
| 691 | 691 | $extracted_fields_to_include[] = $field_sans_model_name; |
| 692 | - }elseif( $field_to_include == $model_name ){ |
|
| 692 | + } elseif( $field_to_include == $model_name ){ |
|
| 693 | 693 | $extracted_fields_to_include[] = '*'; |
| 694 | 694 | } |
| 695 | 695 | } |
| 696 | - }else{ |
|
| 696 | + } else{ |
|
| 697 | 697 | //look for ones with no period |
| 698 | 698 | foreach( $includes as $field_to_include ) { |
| 699 | 699 | $field_to_include = trim( $field_to_include ); |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace EventEspresso\core\libraries\rest_api\controllers\model; |
| 3 | 3 | use EventEspresso\core\libraries\rest_api\Capabilities; |
| 4 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 5 | - exit( 'No direct script access allowed' ); |
|
| 4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function __construct() { |
| 26 | 26 | parent::__construct(); |
| 27 | - \EE_Registry::instance()->load_helper( 'Inflector' ); |
|
| 27 | + \EE_Registry::instance()->load_helper('Inflector'); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -32,22 +32,22 @@ discard block |
||
| 32 | 32 | * @param \WP_REST_Request $request |
| 33 | 33 | * @return \WP_REST_Response|\WP_Error |
| 34 | 34 | */ |
| 35 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
| 35 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
| 36 | 36 | $controller = new Read(); |
| 37 | - try{ |
|
| 37 | + try { |
|
| 38 | 38 | $matches = $controller->parse_route( |
| 39 | 39 | $request->get_route(), |
| 40 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
| 41 | - array( 'version', 'model' ) |
|
| 40 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
| 41 | + array('version', 'model') |
|
| 42 | 42 | ); |
| 43 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
| 44 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
| 45 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
| 43 | + $controller->set_requested_version($matches['version']); |
|
| 44 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 45 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 46 | 46 | return $controller->send_response( |
| 47 | 47 | new \WP_Error( |
| 48 | 48 | 'endpoint_parsing_error', |
| 49 | 49 | sprintf( |
| 50 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 50 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 51 | 51 | $model_name_singular |
| 52 | 52 | ) |
| 53 | 53 | ) |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | return $controller->send_response( |
| 57 | 57 | $controller->get_entities_from_model( |
| 58 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
| 58 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 59 | 59 | $request |
| 60 | 60 | ) |
| 61 | 61 | ); |
| 62 | - } catch( \Exception $e ) { |
|
| 63 | - return $controller->send_response( $e ); |
|
| 62 | + } catch (\Exception $e) { |
|
| 63 | + return $controller->send_response($e); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -70,21 +70,21 @@ discard block |
||
| 70 | 70 | * @param \WP_Rest_Request $request |
| 71 | 71 | * @return \WP_REST_Response|\WP_Error |
| 72 | 72 | */ |
| 73 | - public static function handle_request_get_one( \WP_Rest_Request $request ) { |
|
| 73 | + public static function handle_request_get_one(\WP_Rest_Request $request) { |
|
| 74 | 74 | $controller = new Read(); |
| 75 | - try{ |
|
| 75 | + try { |
|
| 76 | 76 | $matches = $controller->parse_route( |
| 77 | 77 | $request->get_route(), |
| 78 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
| 79 | - array( 'version', 'model', 'id' ) ); |
|
| 80 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
| 81 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
| 82 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
| 78 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
| 79 | + array('version', 'model', 'id') ); |
|
| 80 | + $controller->set_requested_version($matches['version']); |
|
| 81 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 82 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
| 83 | 83 | return $controller->send_response( |
| 84 | 84 | new \WP_Error( |
| 85 | 85 | 'endpoint_parsing_error', |
| 86 | 86 | sprintf( |
| 87 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 87 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 88 | 88 | $model_name_singular |
| 89 | 89 | ) |
| 90 | 90 | ) |
@@ -92,12 +92,12 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | return $controller->send_response( |
| 94 | 94 | $controller->get_entity_from_model( |
| 95 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
| 95 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
| 96 | 96 | $request |
| 97 | 97 | ) |
| 98 | 98 | ); |
| 99 | - } catch( \Exception $e ) { |
|
| 100 | - return $controller->send_response( $e ); |
|
| 99 | + } catch (\Exception $e) { |
|
| 100 | + return $controller->send_response($e); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
@@ -109,35 +109,35 @@ discard block |
||
| 109 | 109 | * @param \WP_REST_Request $request |
| 110 | 110 | * @return \WP_REST_Response|\WP_Error |
| 111 | 111 | */ |
| 112 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
| 112 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
| 113 | 113 | $controller = new Read(); |
| 114 | - try{ |
|
| 114 | + try { |
|
| 115 | 115 | $matches = $controller->parse_route( |
| 116 | 116 | $request->get_route(), |
| 117 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
| 118 | - array( 'version', 'model', 'id', 'related_model' ) |
|
| 117 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
| 118 | + array('version', 'model', 'id', 'related_model') |
|
| 119 | 119 | ); |
| 120 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
| 121 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
| 122 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
| 120 | + $controller->set_requested_version($matches['version']); |
|
| 121 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
| 122 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
| 123 | 123 | return $controller->send_response( |
| 124 | 124 | new \WP_Error( |
| 125 | 125 | 'endpoint_parsing_error', |
| 126 | 126 | sprintf( |
| 127 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 127 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 128 | 128 | $main_model_name_singular |
| 129 | 129 | ) |
| 130 | 130 | ) |
| 131 | 131 | ); |
| 132 | 132 | } |
| 133 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
| 134 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
| 135 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
| 133 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
| 134 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
| 135 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
| 136 | 136 | return $controller->send_response( |
| 137 | 137 | new \WP_Error( |
| 138 | 138 | 'endpoint_parsing_error', |
| 139 | 139 | sprintf( |
| 140 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
| 140 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
| 141 | 141 | $related_model_name_singular |
| 142 | 142 | ) |
| 143 | 143 | ) |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | return $controller->send_response( |
| 148 | 148 | $controller->get_entities_from_relation( |
| 149 | - $request->get_param( 'id' ), |
|
| 150 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
| 149 | + $request->get_param('id'), |
|
| 150 | + $main_model->related_settings_for($related_model_name_singular), |
|
| 151 | 151 | $request |
| 152 | 152 | ) |
| 153 | 153 | ); |
| 154 | - } catch( \Exception $e ) { |
|
| 155 | - return $controller->send_response( $e ); |
|
| 154 | + } catch (\Exception $e) { |
|
| 155 | + return $controller->send_response($e); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
@@ -165,30 +165,30 @@ discard block |
||
| 165 | 165 | * @param \WP_REST_Request $request |
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | - public function get_entities_from_model( $model, $request) { |
|
| 169 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
| 170 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
| 171 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
| 168 | + public function get_entities_from_model($model, $request) { |
|
| 169 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
| 170 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
| 171 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 172 | 172 | return new \WP_Error( |
| 173 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
| 173 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
| 174 | 174 | sprintf( |
| 175 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
| 175 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
| 176 | 176 | $model_name_plural, |
| 177 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
| 177 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
| 178 | 178 | ), |
| 179 | - array( 'status' => 403 ) |
|
| 179 | + array('status' => 403) |
|
| 180 | 180 | ); |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
| 184 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
| 183 | + $this->_set_debug_info('model query params', $query_params); |
|
| 184 | + $results = $model->get_all_wpdb_results($query_params); |
|
| 185 | 185 | $nice_results = array( ); |
| 186 | - foreach ( $results as $result ) { |
|
| 187 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
| 186 | + foreach ($results as $result) { |
|
| 187 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
| 188 | 188 | $model, |
| 189 | 189 | $result, |
| 190 | - $request->get_param( 'include' ), |
|
| 191 | - $query_params[ 'caps' ] |
|
| 190 | + $request->get_param('include'), |
|
| 191 | + $query_params['caps'] |
|
| 192 | 192 | ); |
| 193 | 193 | } |
| 194 | 194 | return $nice_results; |
@@ -205,82 +205,82 @@ discard block |
||
| 205 | 205 | * @param \WP_REST_Request $request |
| 206 | 206 | * @return array |
| 207 | 207 | */ |
| 208 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
| 209 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
| 208 | + public function get_entities_from_relation($id, $relation, $request) { |
|
| 209 | + $context = $this->validate_context($request->get_param('caps')); |
|
| 210 | 210 | $model = $relation->get_this_model(); |
| 211 | 211 | $related_model = $relation->get_other_model(); |
| 212 | 212 | //check if they can access the 1st model object |
| 213 | - $query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 ); |
|
| 214 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
| 213 | + $query_params = array(array($model->primary_key_name() => $id), 'limit' => 1); |
|
| 214 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 215 | 215 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
| 216 | 216 | } |
| 217 | 217 | $restricted_query_params = $query_params; |
| 218 | - $restricted_query_params[ 'caps' ] = $context; |
|
| 219 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
| 220 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
| 218 | + $restricted_query_params['caps'] = $context; |
|
| 219 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
| 220 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
| 221 | 221 | |
| 222 | - if( |
|
| 222 | + if ( |
|
| 223 | 223 | ! ( |
| 224 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
| 225 | - && $model->exists( $restricted_query_params ) |
|
| 224 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
| 225 | + && $model->exists($restricted_query_params) |
|
| 226 | 226 | ) |
| 227 | - ){ |
|
| 228 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
| 229 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
| 230 | - }else{ |
|
| 231 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
| 227 | + ) { |
|
| 228 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 229 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
| 230 | + } else { |
|
| 231 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
| 232 | 232 | } |
| 233 | 233 | return new \WP_Error( |
| 234 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
| 234 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
| 235 | 235 | sprintf( |
| 236 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
| 236 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
| 237 | 237 | $related_model_name_maybe_plural, |
| 238 | 238 | $relation->get_this_model()->get_this_model_name(), |
| 239 | 239 | implode( |
| 240 | 240 | ',', |
| 241 | 241 | array_keys( |
| 242 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
| 242 | + Capabilities::get_missing_permissions($related_model, $context) |
|
| 243 | 243 | ) |
| 244 | 244 | ) |
| 245 | 245 | ), |
| 246 | - array( 'status' => 403 ) |
|
| 246 | + array('status' => 403) |
|
| 247 | 247 | ); |
| 248 | 248 | } |
| 249 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
| 250 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id; |
|
| 251 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
| 252 | - $query_params[ 'caps' ] = $context; |
|
| 253 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
| 254 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
| 249 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
| 250 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id; |
|
| 251 | + $query_params['default_where_conditions'] = 'none'; |
|
| 252 | + $query_params['caps'] = $context; |
|
| 253 | + $this->_set_debug_info('model query params', $query_params); |
|
| 254 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
| 255 | 255 | $nice_results = array(); |
| 256 | - foreach( $results as $result ) { |
|
| 256 | + foreach ($results as $result) { |
|
| 257 | 257 | $nice_result = $this->create_entity_from_wpdb_result( |
| 258 | 258 | $relation->get_other_model(), |
| 259 | 259 | $result, |
| 260 | - $request->get_param( 'include' ), |
|
| 261 | - $query_params[ 'caps' ] |
|
| 260 | + $request->get_param('include'), |
|
| 261 | + $query_params['caps'] |
|
| 262 | 262 | ); |
| 263 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
| 263 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
| 264 | 264 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
| 265 | 265 | //if there are conflicts we prefer the properties from the main model |
| 266 | 266 | $join_model_result = $this->create_entity_from_wpdb_result( |
| 267 | 267 | $relation->get_join_model(), |
| 268 | 268 | $result, |
| 269 | - $request->get_param( 'include' ), |
|
| 270 | - $query_params[ 'caps' ] |
|
| 269 | + $request->get_param('include'), |
|
| 270 | + $query_params['caps'] |
|
| 271 | 271 | ); |
| 272 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
| 272 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
| 273 | 273 | //but keep the meta stuff from the main model |
| 274 | - if( isset( $nice_result['meta'] ) ){ |
|
| 274 | + if (isset($nice_result['meta'])) { |
|
| 275 | 275 | $joined_result['meta'] = $nice_result['meta']; |
| 276 | 276 | } |
| 277 | 277 | $nice_result = $joined_result; |
| 278 | 278 | } |
| 279 | 279 | $nice_results[] = $nice_result; |
| 280 | 280 | } |
| 281 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
| 282 | - return array_shift( $nice_results ); |
|
| 283 | - }else{ |
|
| 281 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
| 282 | + return array_shift($nice_results); |
|
| 283 | + } else { |
|
| 284 | 284 | return $nice_results; |
| 285 | 285 | } |
| 286 | 286 | } |
@@ -317,110 +317,110 @@ discard block |
||
| 317 | 317 | * @param string $context one of the return values from EEM_Base::valid_cap_contexts() |
| 318 | 318 | * @return array ready for being converted into json for sending to client |
| 319 | 319 | */ |
| 320 | - public function create_entity_from_wpdb_result( $model, $db_row, $include, $context ) { |
|
| 321 | - if( $include == null ) { |
|
| 320 | + public function create_entity_from_wpdb_result($model, $db_row, $include, $context) { |
|
| 321 | + if ($include == null) { |
|
| 322 | 322 | $include = '*'; |
| 323 | 323 | } |
| 324 | - if( $context == null ) { |
|
| 324 | + if ($context == null) { |
|
| 325 | 325 | $context = \EEM_Base::caps_read; |
| 326 | 326 | } |
| 327 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
| 328 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
| 329 | - foreach( $result as $field_name => $raw_field_value ) { |
|
| 327 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
| 328 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
| 329 | + foreach ($result as $field_name => $raw_field_value) { |
|
| 330 | 330 | $field_obj = $model->field_settings_for($field_name); |
| 331 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
| 332 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
| 333 | - unset( $result[ $field_name ] ); |
|
| 334 | - }elseif( |
|
| 335 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
| 336 | - ){ |
|
| 337 | - $result[ $field_name ] = array( |
|
| 338 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
| 339 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
| 331 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
| 332 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
| 333 | + unset($result[$field_name]); |
|
| 334 | + }elseif ( |
|
| 335 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
| 336 | + ) { |
|
| 337 | + $result[$field_name] = array( |
|
| 338 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 339 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
| 340 | 340 | ); |
| 341 | - }elseif( |
|
| 342 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
| 343 | - ){ |
|
| 344 | - $result[ $field_name ] = array( |
|
| 345 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
| 346 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
| 341 | + }elseif ( |
|
| 342 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
| 343 | + ) { |
|
| 344 | + $result[$field_name] = array( |
|
| 345 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
| 346 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
| 347 | 347 | ); |
| 348 | - }elseif( $field_obj instanceof \EE_Datetime_Field ){ |
|
| 349 | - if( $raw_field_value instanceof \DateTime ) { |
|
| 350 | - $raw_field_value = $raw_field_value->format( 'c' ); |
|
| 348 | + }elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
| 349 | + if ($raw_field_value instanceof \DateTime) { |
|
| 350 | + $raw_field_value = $raw_field_value->format('c'); |
|
| 351 | 351 | } |
| 352 | - $result[ $field_name ] = mysql_to_rfc3339( $raw_field_value ); |
|
| 353 | - }else{ |
|
| 354 | - $value_prepared = $field_obj->prepare_for_get( $field_value ); |
|
| 352 | + $result[$field_name] = mysql_to_rfc3339($raw_field_value); |
|
| 353 | + } else { |
|
| 354 | + $value_prepared = $field_obj->prepare_for_get($field_value); |
|
| 355 | 355 | |
| 356 | - $result[ $field_name ] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared; |
|
| 356 | + $result[$field_name] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared; |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | - if( $model instanceof \EEM_CPT_Base ) { |
|
| 359 | + if ($model instanceof \EEM_CPT_Base) { |
|
| 360 | 360 | $attachment = wp_get_attachment_image_src( |
| 361 | - get_post_thumbnail_id( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
| 361 | + get_post_thumbnail_id($db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
| 362 | 362 | 'full' |
| 363 | 363 | ); |
| 364 | - $result[ 'featured_image_url' ] = !empty( $attachment ) ? $attachment[ 0 ] : null; |
|
| 365 | - $result[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
| 364 | + $result['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null; |
|
| 365 | + $result['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
| 366 | 366 | } |
| 367 | 367 | //add links to related data |
| 368 | 368 | $result['_links'] = array( |
| 369 | 369 | 'self' => array( |
| 370 | 370 | array( |
| 371 | 371 | 'href' => $this->get_versioned_link_to( |
| 372 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $result[ $model->primary_key_name() ] |
|
| 372 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$result[$model->primary_key_name()] |
|
| 373 | 373 | ) |
| 374 | 374 | ) |
| 375 | 375 | ), |
| 376 | 376 | 'collection' => array( |
| 377 | 377 | array( |
| 378 | 378 | 'href' => $this->get_versioned_link_to( |
| 379 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
| 379 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
| 380 | 380 | ) |
| 381 | 381 | ) |
| 382 | 382 | ), |
| 383 | 383 | ); |
| 384 | 384 | global $wp_rest_server; |
| 385 | - if( $model instanceof \EEM_CPT_Base && |
|
| 385 | + if ($model instanceof \EEM_CPT_Base && |
|
| 386 | 386 | $wp_rest_server instanceof \WP_REST_Server && |
| 387 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) ) { |
|
| 388 | - $result[ '_links' ][ 'https://api.eventespresso.com/self_wp_post' ] = array( |
|
| 387 | + $wp_rest_server->get_route_options('/wp/v2/posts')) { |
|
| 388 | + $result['_links']['https://api.eventespresso.com/self_wp_post'] = array( |
|
| 389 | 389 | array( |
| 390 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
| 390 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
| 391 | 391 | 'single' => true |
| 392 | 392 | ) |
| 393 | 393 | ); |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | //filter fields if specified |
| 397 | - $includes_for_this_model = $this->extract_includes_for_this_model( $include ); |
|
| 398 | - if( ! empty( $includes_for_this_model ) ) { |
|
| 399 | - if( $model->has_primary_key_field() ) { |
|
| 397 | + $includes_for_this_model = $this->extract_includes_for_this_model($include); |
|
| 398 | + if ( ! empty($includes_for_this_model)) { |
|
| 399 | + if ($model->has_primary_key_field()) { |
|
| 400 | 400 | //always include the primary key |
| 401 | 401 | $includes_for_this_model[] = $model->primary_key_name(); |
| 402 | 402 | } |
| 403 | - $result = array_intersect_key( $result, array_flip( $includes_for_this_model ) ); |
|
| 403 | + $result = array_intersect_key($result, array_flip($includes_for_this_model)); |
|
| 404 | 404 | } |
| 405 | 405 | //add meta links and possibly include related models |
| 406 | 406 | $relation_settings = apply_filters( |
| 407 | 407 | 'FHEE__Read__create_entity_from_wpdb_result__related_models_to_include', |
| 408 | 408 | $model->relation_settings() |
| 409 | 409 | ); |
| 410 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
| 411 | - $related_model_part = $this->get_related_entity_name( $relation_name, $relation_obj ); |
|
| 412 | - if( empty( $includes_for_this_model ) || isset( $includes_for_this_model['meta'] ) ) { |
|
| 413 | - $result['_links']['https://api.eventespresso.com/' . $related_model_part] = array( |
|
| 410 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
| 411 | + $related_model_part = $this->get_related_entity_name($relation_name, $relation_obj); |
|
| 412 | + if (empty($includes_for_this_model) || isset($includes_for_this_model['meta'])) { |
|
| 413 | + $result['_links']['https://api.eventespresso.com/'.$related_model_part] = array( |
|
| 414 | 414 | array( |
| 415 | 415 | 'href' => $this->get_versioned_link_to( |
| 416 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $result[ $model->primary_key_name() ] . '/' . $related_model_part |
|
| 416 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$result[$model->primary_key_name()].'/'.$related_model_part |
|
| 417 | 417 | ), |
| 418 | 418 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
| 419 | 419 | ) |
| 420 | 420 | ); |
| 421 | 421 | } |
| 422 | - $related_fields_to_include = $this->extract_includes_for_this_model( $include, $relation_name ); |
|
| 423 | - if( $related_fields_to_include ) { |
|
| 422 | + $related_fields_to_include = $this->extract_includes_for_this_model($include, $relation_name); |
|
| 423 | + if ($related_fields_to_include) { |
|
| 424 | 424 | $pretend_related_request = new \WP_REST_Request(); |
| 425 | 425 | $pretend_related_request->set_query_params( |
| 426 | 426 | array( |
@@ -432,11 +432,11 @@ discard block |
||
| 432 | 432 | ) |
| 433 | 433 | ); |
| 434 | 434 | $related_results = $this->get_entities_from_relation( |
| 435 | - $result[ $model->primary_key_name() ], |
|
| 435 | + $result[$model->primary_key_name()], |
|
| 436 | 436 | $relation_obj, |
| 437 | 437 | $pretend_related_request |
| 438 | 438 | ); |
| 439 | - $result[ $related_model_part ] = $related_results instanceof \WP_Error ? null : $related_results; |
|
| 439 | + $result[$related_model_part] = $related_results instanceof \WP_Error ? null : $related_results; |
|
| 440 | 440 | } |
| 441 | 441 | } |
| 442 | 442 | $result = apply_filters( |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | ); |
| 454 | 454 | $this->_set_debug_info( |
| 455 | 455 | 'inaccessible fields', |
| 456 | - array_keys( array_diff_key( $result, $result_without_inaccessible_fields ) ) |
|
| 456 | + array_keys(array_diff_key($result, $result_without_inaccessible_fields)) |
|
| 457 | 457 | ); |
| 458 | 458 | return apply_filters( |
| 459 | 459 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
@@ -468,8 +468,8 @@ discard block |
||
| 468 | 468 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
| 469 | 469 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
| 470 | 470 | */ |
| 471 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
| 472 | - return rest_url( \EED_Core_Rest_Api::ee_api_namespace . $this->get_model_version_info()->requested_version() . '/' . $link_part_after_version_and_slash ); |
|
| 471 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
| 472 | + return rest_url(\EED_Core_Rest_Api::ee_api_namespace.$this->get_model_version_info()->requested_version().'/'.$link_part_after_version_and_slash); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | /** |
@@ -479,11 +479,11 @@ discard block |
||
| 479 | 479 | * @param \EE_Model_Relation_Base $relation_obj |
| 480 | 480 | * @return string |
| 481 | 481 | */ |
| 482 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
| 483 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
| 484 | - return strtolower( $relation_name ); |
|
| 485 | - }else{ |
|
| 486 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
| 482 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
| 483 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
| 484 | + return strtolower($relation_name); |
|
| 485 | + } else { |
|
| 486 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | |
@@ -496,44 +496,44 @@ discard block |
||
| 496 | 496 | * @param \WP_REST_Request $request |
| 497 | 497 | * @return array |
| 498 | 498 | */ |
| 499 | - public function get_entity_from_model( $model, $request ) { |
|
| 500 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
| 501 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
| 499 | + public function get_entity_from_model($model, $request) { |
|
| 500 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
| 501 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
| 502 | 502 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
| 503 | 503 | } |
| 504 | 504 | $restricted_query_params = $query_params; |
| 505 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
| 506 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
| 507 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
| 508 | - if ( ! empty ( $model_rows ) ) { |
|
| 505 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
| 506 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
| 507 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
| 508 | + if ( ! empty ($model_rows)) { |
|
| 509 | 509 | return $this->create_entity_from_wpdb_result( |
| 510 | 510 | $model, |
| 511 | - array_shift( $model_rows ), |
|
| 512 | - $request->get_param( 'include' ), |
|
| 513 | - $this->validate_context( $request->get_param( 'caps' ) ) ); |
|
| 511 | + array_shift($model_rows), |
|
| 512 | + $request->get_param('include'), |
|
| 513 | + $this->validate_context($request->get_param('caps')) ); |
|
| 514 | 514 | } else { |
| 515 | 515 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
| 516 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
| 517 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
| 518 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
| 516 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
| 517 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
| 518 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
| 519 | 519 | //you got shafted- it existed but we didn't want to tell you! |
| 520 | 520 | return new \WP_Error( |
| 521 | 521 | 'rest_user_cannot_read', |
| 522 | 522 | sprintf( |
| 523 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
| 524 | - strtolower( $model->get_this_model_name() ), |
|
| 523 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
| 524 | + strtolower($model->get_this_model_name()), |
|
| 525 | 525 | Capabilities::get_missing_permissions_string( |
| 526 | 526 | $model, |
| 527 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
| 527 | + $this->validate_context($request->get_param('caps')) ) |
|
| 528 | 528 | ), |
| 529 | - array( 'status' => 403 ) |
|
| 529 | + array('status' => 403) |
|
| 530 | 530 | ); |
| 531 | 531 | } else { |
| 532 | 532 | //it's not you. It just doesn't exist |
| 533 | 533 | return new \WP_Error( |
| 534 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
| 535 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
| 536 | - array( 'status' => 404 ) |
|
| 534 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
| 535 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
| 536 | + array('status' => 404) |
|
| 537 | 537 | ); |
| 538 | 538 | } |
| 539 | 539 | } |
@@ -546,14 +546,14 @@ discard block |
||
| 546 | 546 | * @param string $context |
| 547 | 547 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
| 548 | 548 | */ |
| 549 | - public function validate_context( $context ) { |
|
| 550 | - if( ! $context ) { |
|
| 549 | + public function validate_context($context) { |
|
| 550 | + if ( ! $context) { |
|
| 551 | 551 | $context = \EEM_Base::caps_read; |
| 552 | 552 | } |
| 553 | 553 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
| 554 | - if( in_array( $context, $valid_contexts ) ){ |
|
| 554 | + if (in_array($context, $valid_contexts)) { |
|
| 555 | 555 | return $context; |
| 556 | - }else{ |
|
| 556 | + } else { |
|
| 557 | 557 | return \EEM_Base::caps_read; |
| 558 | 558 | } |
| 559 | 559 | } |
@@ -569,73 +569,73 @@ discard block |
||
| 569 | 569 | * that absolutely no results should be returned |
| 570 | 570 | * @throws \EE_Error |
| 571 | 571 | */ |
| 572 | - public function create_model_query_params( $model, $query_parameters ) { |
|
| 572 | + public function create_model_query_params($model, $query_parameters) { |
|
| 573 | 573 | $model_query_params = array( ); |
| 574 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
| 575 | - $model_query_params[ 0 ] = $this->prepare_rest_query_params_key_for_models( $model, $query_parameters[ 'where' ] ); |
|
| 576 | - } |
|
| 577 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
| 578 | - $order_by = $query_parameters[ 'order_by' ]; |
|
| 579 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
| 580 | - $order_by = $query_parameters[ 'orderby' ]; |
|
| 581 | - }else{ |
|
| 574 | + if (isset($query_parameters['where'])) { |
|
| 575 | + $model_query_params[0] = $this->prepare_rest_query_params_key_for_models($model, $query_parameters['where']); |
|
| 576 | + } |
|
| 577 | + if (isset($query_parameters['order_by'])) { |
|
| 578 | + $order_by = $query_parameters['order_by']; |
|
| 579 | + } elseif (isset($query_parameters['orderby'])) { |
|
| 580 | + $order_by = $query_parameters['orderby']; |
|
| 581 | + } else { |
|
| 582 | 582 | $order_by = null; |
| 583 | 583 | } |
| 584 | - if( $order_by !== null ){ |
|
| 585 | - $model_query_params[ 'order_by' ] = $this->prepare_rest_query_params_key_for_models( $model, $order_by ); |
|
| 584 | + if ($order_by !== null) { |
|
| 585 | + $model_query_params['order_by'] = $this->prepare_rest_query_params_key_for_models($model, $order_by); |
|
| 586 | 586 | } |
| 587 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
| 588 | - $group_by = $query_parameters[ 'group_by' ]; |
|
| 589 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
| 590 | - $group_by = $query_parameters[ 'groupby' ]; |
|
| 591 | - }else{ |
|
| 587 | + if (isset($query_parameters['group_by'])) { |
|
| 588 | + $group_by = $query_parameters['group_by']; |
|
| 589 | + } elseif (isset($query_parameters['groupby'])) { |
|
| 590 | + $group_by = $query_parameters['groupby']; |
|
| 591 | + } else { |
|
| 592 | 592 | $group_by = null; |
| 593 | 593 | } |
| 594 | - if( $group_by !== null ){ |
|
| 595 | - if( is_array( $group_by ) ) { |
|
| 596 | - $group_by = $this->prepare_rest_query_params_values_for_models( $model, $group_by ); |
|
| 594 | + if ($group_by !== null) { |
|
| 595 | + if (is_array($group_by)) { |
|
| 596 | + $group_by = $this->prepare_rest_query_params_values_for_models($model, $group_by); |
|
| 597 | 597 | } |
| 598 | - $model_query_params[ 'group_by' ] = $group_by; |
|
| 598 | + $model_query_params['group_by'] = $group_by; |
|
| 599 | 599 | } |
| 600 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
| 600 | + if (isset($query_parameters['having'])) { |
|
| 601 | 601 | //@todo: no good for permissions |
| 602 | - $model_query_params[ 'having' ] = $this->prepare_rest_query_params_key_for_models( $model, $query_parameters[ 'having' ] ); |
|
| 602 | + $model_query_params['having'] = $this->prepare_rest_query_params_key_for_models($model, $query_parameters['having']); |
|
| 603 | 603 | } |
| 604 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
| 605 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
| 604 | + if (isset($query_parameters['order'])) { |
|
| 605 | + $model_query_params['order'] = $query_parameters['order']; |
|
| 606 | 606 | } |
| 607 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
| 608 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
| 607 | + if (isset($query_parameters['mine'])) { |
|
| 608 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
| 609 | 609 | } |
| 610 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
| 610 | + if (isset($query_parameters['limit'])) { |
|
| 611 | 611 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
| 612 | - if( is_string( $query_parameters[ 'limit' ] ) ) { |
|
| 612 | + if (is_string($query_parameters['limit'])) { |
|
| 613 | 613 | $limit_array = explode(',', $query_parameters['limit']); |
| 614 | - }else { |
|
| 615 | - $limit_array = $query_parameters[ 'limit' ]; |
|
| 614 | + } else { |
|
| 615 | + $limit_array = $query_parameters['limit']; |
|
| 616 | 616 | } |
| 617 | 617 | $sanitized_limit = array(); |
| 618 | - foreach( $limit_array as $key => $limit_part ) { |
|
| 619 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
| 618 | + foreach ($limit_array as $key => $limit_part) { |
|
| 619 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
| 620 | 620 | throw new \EE_Error( |
| 621 | 621 | sprintf( |
| 622 | - __( 'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso' ), |
|
| 623 | - json_encode( $query_parameters[ 'limit' ] ) |
|
| 622 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso'), |
|
| 623 | + json_encode($query_parameters['limit']) |
|
| 624 | 624 | ) |
| 625 | 625 | ); |
| 626 | 626 | } |
| 627 | - $sanitized_limit[] = intval( $limit_part ); |
|
| 627 | + $sanitized_limit[] = intval($limit_part); |
|
| 628 | 628 | } |
| 629 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
| 630 | - }else{ |
|
| 631 | - $model_query_params[ 'limit' ] = 50; |
|
| 629 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
| 630 | + } else { |
|
| 631 | + $model_query_params['limit'] = 50; |
|
| 632 | 632 | } |
| 633 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
| 634 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
| 635 | - }else{ |
|
| 636 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
| 633 | + if (isset($query_parameters['caps'])) { |
|
| 634 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
| 635 | + } else { |
|
| 636 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
| 637 | 637 | } |
| 638 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
| 638 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | |
@@ -647,24 +647,24 @@ discard block |
||
| 647 | 647 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
| 648 | 648 | * @return array |
| 649 | 649 | */ |
| 650 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
| 650 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
| 651 | 651 | $model_ready_query_params = array(); |
| 652 | - foreach( $query_params as $key => $value ) { |
|
| 653 | - if( is_array( $value ) ) { |
|
| 654 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
| 655 | - }else{ |
|
| 656 | - $model_ready_query_params[ $key ] = $value; |
|
| 652 | + foreach ($query_params as $key => $value) { |
|
| 653 | + if (is_array($value)) { |
|
| 654 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
| 655 | + } else { |
|
| 656 | + $model_ready_query_params[$key] = $value; |
|
| 657 | 657 | } |
| 658 | 658 | } |
| 659 | 659 | return $model_ready_query_params; |
| 660 | 660 | } |
| 661 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
| 661 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
| 662 | 662 | $model_ready_query_params = array(); |
| 663 | - foreach( $query_params as $key => $value ) { |
|
| 664 | - if( is_array( $value ) ) { |
|
| 665 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
| 663 | + foreach ($query_params as $key => $value) { |
|
| 664 | + if (is_array($value)) { |
|
| 665 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
| 666 | 666 | } else { |
| 667 | - $model_ready_query_params[ $key ] = $value; |
|
| 667 | + $model_ready_query_params[$key] = $value; |
|
| 668 | 668 | } |
| 669 | 669 | } |
| 670 | 670 | return $model_ready_query_params; |
@@ -680,33 +680,33 @@ discard block |
||
| 680 | 680 | * @return array of fields for this model. If $model_name is provided, then |
| 681 | 681 | * the fields for that model, with the model's name removed from each. |
| 682 | 682 | */ |
| 683 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
| 684 | - if( is_array( $include_string ) ) { |
|
| 685 | - $include_string = implode( ',', $include_string ); |
|
| 683 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
| 684 | + if (is_array($include_string)) { |
|
| 685 | + $include_string = implode(',', $include_string); |
|
| 686 | 686 | } |
| 687 | - if( $include_string === '*' ) { |
|
| 687 | + if ($include_string === '*') { |
|
| 688 | 688 | return array(); |
| 689 | 689 | } |
| 690 | - $includes = explode( ',', $include_string ); |
|
| 690 | + $includes = explode(',', $include_string); |
|
| 691 | 691 | $extracted_fields_to_include = array(); |
| 692 | - if( $model_name ){ |
|
| 693 | - foreach( $includes as $field_to_include ) { |
|
| 694 | - $field_to_include = trim( $field_to_include ); |
|
| 695 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
| 692 | + if ($model_name) { |
|
| 693 | + foreach ($includes as $field_to_include) { |
|
| 694 | + $field_to_include = trim($field_to_include); |
|
| 695 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
| 696 | 696 | //found the model name at the exact start |
| 697 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
| 697 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
| 698 | 698 | $extracted_fields_to_include[] = $field_sans_model_name; |
| 699 | - }elseif( $field_to_include == $model_name ){ |
|
| 699 | + }elseif ($field_to_include == $model_name) { |
|
| 700 | 700 | $extracted_fields_to_include[] = '*'; |
| 701 | 701 | } |
| 702 | 702 | } |
| 703 | - }else{ |
|
| 703 | + } else { |
|
| 704 | 704 | //look for ones with no period |
| 705 | - foreach( $includes as $field_to_include ) { |
|
| 706 | - $field_to_include = trim( $field_to_include ); |
|
| 705 | + foreach ($includes as $field_to_include) { |
|
| 706 | + $field_to_include = trim($field_to_include); |
|
| 707 | 707 | if ( |
| 708 | - strpos( $field_to_include, '.' ) === false |
|
| 709 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
| 708 | + strpos($field_to_include, '.') === false |
|
| 709 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
| 710 | 710 | ) { |
| 711 | 711 | $extracted_fields_to_include[] = $field_to_include; |
| 712 | 712 | } |
@@ -7,6 +7,10 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | protected $_post_type; |
| 9 | 9 | protected $_meta_field; |
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * @param string $post_type |
|
| 13 | + */ |
|
| 10 | 14 | function __construct($post_type, $meta_field_to_chk = ''){ |
| 11 | 15 | $this->_post_type = $post_type; |
| 12 | 16 | $this->_meta_field = $meta_field_to_chk; |
@@ -27,7 +31,6 @@ discard block |
||
| 27 | 31 | } |
| 28 | 32 | /** |
| 29 | 33 | * Gets the where default where conditions for a custom post type model |
| 30 | - * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment" |
|
| 31 | 34 | * @return array like EEM_Base::get_all's $query_params's index [0] (where conditions) |
| 32 | 35 | */ |
| 33 | 36 | protected function _get_default_where_conditions() { |
@@ -3,11 +3,11 @@ discard block |
||
| 3 | 3 | /* |
| 4 | 4 | * Strategy specifically for adding where conditions specific to CPT models. |
| 5 | 5 | */ |
| 6 | -class EE_CPT_Where_Conditions extends EE_Default_Where_Conditions{ |
|
| 6 | +class EE_CPT_Where_Conditions extends EE_Default_Where_Conditions { |
|
| 7 | 7 | |
| 8 | 8 | protected $_post_type; |
| 9 | 9 | protected $_meta_field; |
| 10 | - function __construct($post_type, $meta_field_to_chk = ''){ |
|
| 10 | + function __construct($post_type, $meta_field_to_chk = '') { |
|
| 11 | 11 | $this->_post_type = $post_type; |
| 12 | 12 | $this->_meta_field = $meta_field_to_chk; |
| 13 | 13 | } |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | * @param string $column column name |
| 18 | 18 | * @return EE_Model_Field_Base |
| 19 | 19 | */ |
| 20 | - protected function _get_field_on_column($column){ |
|
| 20 | + protected function _get_field_on_column($column) { |
|
| 21 | 21 | $all_fields = $this->_model->field_settings(true); |
| 22 | - foreach($all_fields as $field_name => $field_obj){ |
|
| 23 | - if($column == $field_obj->get_table_column()){ |
|
| 22 | + foreach ($all_fields as $field_name => $field_obj) { |
|
| 23 | + if ($column == $field_obj->get_table_column()) { |
|
| 24 | 24 | return $field_obj; |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | //find post_type field |
| 35 | 35 | $post_type_field = $this->_get_field_on_column('post_type'); |
| 36 | 36 | $status_field = $this->_get_field_on_column('post_status'); |
| 37 | - return array( $post_type_field->get_name() => $this->_post_type, |
|
| 38 | - $status_field->get_name() => array('NOT IN',array('auto-draft','trash')) |
|
| 37 | + return array($post_type_field->get_name() => $this->_post_type, |
|
| 38 | + $status_field->get_name() => array('NOT IN', array('auto-draft', 'trash')) |
|
| 39 | 39 | ); |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -126,7 +126,7 @@ |
||
| 126 | 126 | * being address info, and 0 being neither) |
| 127 | 127 | * @global type $wpdb |
| 128 | 128 | * @param type $new_question_group_id |
| 129 | - * @return boolean |
|
| 129 | + * @return integer |
|
| 130 | 130 | */ |
| 131 | 131 | private function _is_system_question_group($new_question_group_id){ |
| 132 | 132 | global $wpdb; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | - public function __construct( $routing = TRUE ) { |
|
| 34 | - define( 'REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS ); |
|
| 35 | - define( 'REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS ); |
|
| 36 | - define( 'REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/' ); |
|
| 37 | - define( 'REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS ); |
|
| 38 | - define( 'REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/' ); |
|
| 39 | - parent::__construct( $routing ); |
|
| 33 | + public function __construct($routing = TRUE) { |
|
| 34 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND.'registration_form'.DS); |
|
| 35 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN.'assets'.DS); |
|
| 36 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/assets/'); |
|
| 37 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN.'templates'.DS); |
|
| 38 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/templates/'); |
|
| 39 | + parent::__construct($routing); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | protected function _extend_page_config() { |
| 48 | 48 | $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
| 49 | - $qst_id = ! empty( $this->_req_data['QST_ID'] ) && ! is_array( $this->_req_data['QST_ID'] ) ? $this->_req_data['QST_ID'] : 0; |
|
| 50 | - $qsg_id = ! empty( $this->_req_data['QSG_ID'] ) && ! is_array( $this->_req_data['QSG_ID'] ) ? $this->_req_data['QSG_ID'] : 0; |
|
| 49 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
| 50 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
|
| 51 | 51 | |
| 52 | 52 | $new_page_routes = array( |
| 53 | 53 | 'question_groups' => array( |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | 'func' => '_trash_or_restore_questions', |
| 81 | 81 | 'capability' => 'ee_delete_question', |
| 82 | 82 | 'obj_id' => $qst_id, |
| 83 | - 'args' => array( 'trash' => FALSE ), |
|
| 83 | + 'args' => array('trash' => FALSE), |
|
| 84 | 84 | 'noheader' => TRUE |
| 85 | 85 | ), |
| 86 | 86 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | 'trash_question_group' => array( |
| 141 | 141 | 'func' => '_trash_or_restore_question_groups', |
| 142 | - 'args' => array( 'trash' => TRUE ), |
|
| 142 | + 'args' => array('trash' => TRUE), |
|
| 143 | 143 | 'capability' => 'ee_delete_question_group', |
| 144 | 144 | 'obj_id' => $qsg_id, |
| 145 | 145 | 'noheader' => TRUE |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | 'restore_question_group' => array( |
| 149 | 149 | 'func' => '_trash_or_restore_question_groups', |
| 150 | - 'args' => array( 'trash' => FALSE ), |
|
| 150 | + 'args' => array('trash' => FALSE), |
|
| 151 | 151 | 'capability' => 'ee_delete_question_group', |
| 152 | 152 | 'obj_id' => $qsg_id, |
| 153 | 153 | 'noheader' => TRUE |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | 'update_question_group' => array( |
| 164 | 164 | 'func' => '_insert_or_update_question_group', |
| 165 | - 'args' => array('new_question_group' => FALSE ), |
|
| 165 | + 'args' => array('new_question_group' => FALSE), |
|
| 166 | 166 | 'capability' => 'ee_edit_question_group', |
| 167 | 167 | 'obj_id' => $qsg_id, |
| 168 | 168 | 'noheader' => TRUE, |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | 'noheader' => TRUE |
| 201 | 201 | ), |
| 202 | 202 | ); |
| 203 | - $this->_page_routes = array_merge( $this->_page_routes, $new_page_routes ); |
|
| 203 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 204 | 204 | |
| 205 | 205 | $new_page_config = array( |
| 206 | 206 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | 'filename' => 'registration_form_question_groups_views_bulk_actions_search' |
| 225 | 225 | ), |
| 226 | 226 | ), |
| 227 | - 'help_tour' => array( 'Registration_Form_Question_Groups_Help_Tour'), |
|
| 227 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 228 | 228 | 'metaboxes' => $this->_default_espresso_metaboxes, |
| 229 | 229 | 'require_nonce' => FALSE, |
| 230 | 230 | 'qtips' => array( |
@@ -238,14 +238,14 @@ discard block |
||
| 238 | 238 | 'order' => 5, |
| 239 | 239 | 'persistent' => FALSE |
| 240 | 240 | ), |
| 241 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
|
| 241 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 242 | 242 | 'help_tabs' => array( |
| 243 | 243 | 'registration_form_add_question_help_tab' => array( |
| 244 | 244 | 'title' => __('Add Question', 'event_espresso'), |
| 245 | 245 | 'filename' => 'registration_form_add_question' |
| 246 | 246 | ), |
| 247 | 247 | ), |
| 248 | - 'help_tour' => array( 'Registration_Form_Add_Question_Help_Tour'), |
|
| 248 | + 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
| 249 | 249 | 'require_nonce' => FALSE |
| 250 | 250 | ), |
| 251 | 251 | |
@@ -255,14 +255,14 @@ discard block |
||
| 255 | 255 | 'order' => 5, |
| 256 | 256 | 'persistent' => FALSE |
| 257 | 257 | ), |
| 258 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
|
| 258 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 259 | 259 | 'help_tabs' => array( |
| 260 | 260 | 'registration_form_add_question_group_help_tab' => array( |
| 261 | 261 | 'title' => __('Add Question Group', 'event_espresso'), |
| 262 | 262 | 'filename' => 'registration_form_add_question_group' |
| 263 | 263 | ), |
| 264 | 264 | ), |
| 265 | - 'help_tour' => array( 'Registration_Form_Add_Question_Group_Help_Tour'), |
|
| 265 | + 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
| 266 | 266 | 'require_nonce' => FALSE |
| 267 | 267 | ), |
| 268 | 268 | |
@@ -271,16 +271,16 @@ discard block |
||
| 271 | 271 | 'label' => __('Edit Question Group', 'event_espresso'), |
| 272 | 272 | 'order' => 5, |
| 273 | 273 | 'persistent' => FALSE, |
| 274 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
|
| 274 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']), $this->_current_page_view_url) : $this->_admin_base_url |
|
| 275 | 275 | ), |
| 276 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
|
| 276 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 277 | 277 | 'help_tabs' => array( |
| 278 | 278 | 'registration_form_edit_question_group_help_tab' => array( |
| 279 | 279 | 'title' => __('Edit Question Group', 'event_espresso'), |
| 280 | 280 | 'filename' => 'registration_form_edit_question_group' |
| 281 | 281 | ), |
| 282 | 282 | ), |
| 283 | - 'help_tour' => array( 'Registration_Form_Edit_Question_Group_Help_Tour'), |
|
| 283 | + 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
| 284 | 284 | 'require_nonce' => FALSE |
| 285 | 285 | ), |
| 286 | 286 | |
@@ -292,19 +292,19 @@ discard block |
||
| 292 | 292 | 'labels' => array( |
| 293 | 293 | 'publishbox' => __('Update Settings', 'event_espresso') |
| 294 | 294 | ), |
| 295 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_publish_post_box' ) ), |
|
| 295 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 296 | 296 | 'help_tabs' => array( |
| 297 | 297 | 'registration_form_reg_form_settings_help_tab' => array( |
| 298 | 298 | 'title' => __('Registration Form Settings', 'event_espresso'), |
| 299 | 299 | 'filename' => 'registration_form_reg_form_settings' |
| 300 | 300 | ), |
| 301 | 301 | ), |
| 302 | - 'help_tour' => array( 'Registration_Form_Settings_Help_Tour'), |
|
| 302 | + 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 303 | 303 | 'require_nonce' => FALSE |
| 304 | 304 | ) |
| 305 | 305 | |
| 306 | 306 | ); |
| 307 | - $this->_page_config = array_merge( $this->_page_config, $new_page_config ); |
|
| 307 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 308 | 308 | |
| 309 | 309 | //change the list table we're going to use so it's the NEW list table! |
| 310 | 310 | $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | 'edit_question_group' => __('Edit Question Group', 'event_espresso'), |
| 319 | 319 | 'delete_question_group' => __('Delete Question Group', 'event_espresso'), |
| 320 | 320 | ); |
| 321 | - $this->_labels['buttons'] = array_merge( $this->_labels['buttons'], $new_labels ); |
|
| 321 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
| 322 | 322 | |
| 323 | 323 | } |
| 324 | 324 | |
@@ -327,14 +327,14 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | |
| 329 | 329 | protected function _ajax_hooks() { |
| 330 | - add_action('wp_ajax_espresso_update_question_group_order', array( $this, 'update_question_group_order' )); |
|
| 330 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | |
| 334 | 334 | |
| 335 | 335 | |
| 336 | 336 | public function load_scripts_styles_question_groups() { |
| 337 | - wp_enqueue_script( 'espresso_ajax_table_sorting' ); |
|
| 337 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | * @return void |
| 356 | 356 | */ |
| 357 | 357 | public function load_sortable_question_script() { |
| 358 | - wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 358 | + wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL.'ee_question_order.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 359 | 359 | wp_enqueue_script('ee-question-sortable'); |
| 360 | 360 | } |
| 361 | 361 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | ) |
| 375 | 375 | ); |
| 376 | 376 | |
| 377 | - if ( EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', 'espresso_registration_form_trash_questions' ) ) { |
|
| 377 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', 'espresso_registration_form_trash_questions')) { |
|
| 378 | 378 | $this->_views['trash'] = array( |
| 379 | 379 | 'slug' => 'trash', |
| 380 | 380 | 'label' => __('Trash', 'event_espresso'), |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | ) |
| 405 | 405 | ); |
| 406 | 406 | |
| 407 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_question_groups', 'espresso_registration_form_trash_question_groups' ) ) { |
|
| 407 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups', 'espresso_registration_form_trash_question_groups')) { |
|
| 408 | 408 | $this->_views['trash'] = array( |
| 409 | 409 | 'slug' => 'trash', |
| 410 | 410 | 'label' => __('Trash', 'event_espresso'), |
@@ -440,24 +440,24 @@ discard block |
||
| 440 | 440 | |
| 441 | 441 | |
| 442 | 442 | |
| 443 | - protected function _delete_question(){ |
|
| 444 | - $success = $this->_delete_items( $this->_question_model ); |
|
| 443 | + protected function _delete_question() { |
|
| 444 | + $success = $this->_delete_items($this->_question_model); |
|
| 445 | 445 | $this->_redirect_after_action( |
| 446 | 446 | $success, |
| 447 | - $this->_question_model->item_name( $success ), |
|
| 447 | + $this->_question_model->item_name($success), |
|
| 448 | 448 | 'deleted', |
| 449 | - array( 'action' => 'default', 'status' => 'all' ) |
|
| 449 | + array('action' => 'default', 'status' => 'all') |
|
| 450 | 450 | ); |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | |
| 454 | 454 | protected function _delete_questions() { |
| 455 | - $success = $this->_delete_items( $this->_question_model ); |
|
| 455 | + $success = $this->_delete_items($this->_question_model); |
|
| 456 | 456 | $this->_redirect_after_action( |
| 457 | 457 | $success, |
| 458 | - $this->_question_model->item_name( $success ), |
|
| 458 | + $this->_question_model->item_name($success), |
|
| 459 | 459 | 'deleted permanently', |
| 460 | - array( 'action' => 'default', 'status' => 'trash' ) |
|
| 460 | + array('action' => 'default', 'status' => 'trash') |
|
| 461 | 461 | ); |
| 462 | 462 | } |
| 463 | 463 | |
@@ -468,26 +468,26 @@ discard block |
||
| 468 | 468 | * @param EEM_Soft_Delete_Base $model |
| 469 | 469 | * @return int number of items deleted permanently |
| 470 | 470 | */ |
| 471 | - private function _delete_items(EEM_Soft_Delete_Base $model){ |
|
| 471 | + private function _delete_items(EEM_Soft_Delete_Base $model) { |
|
| 472 | 472 | $success = 0; |
| 473 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 474 | - if (!empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 473 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 474 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 475 | 475 | // if array has more than one element than success message should be plural |
| 476 | - $success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1; |
|
| 476 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 477 | 477 | // cycle thru bulk action checkboxes |
| 478 | - while (list( $ID, $value ) = each($this->_req_data['checkbox'])) { |
|
| 479 | - if ( ! $this->_delete_item( $ID, $model ) ) { |
|
| 478 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 479 | + if ( ! $this->_delete_item($ID, $model)) { |
|
| 480 | 480 | $success = 0; |
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - }elseif( !empty($this->_req_data['QSG_ID'])){ |
|
| 485 | - $success = $this->_delete_item( $this->_req_data['QSG_ID'], $model ); |
|
| 484 | + }elseif ( ! empty($this->_req_data['QSG_ID'])) { |
|
| 485 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
| 486 | 486 | |
| 487 | - }elseif( !empty($this->_req_data['QST_ID'])){ |
|
| 488 | - $success = $this->_delete_item( $this->_req_data['QST_ID'], $model ); |
|
| 489 | - }else{ |
|
| 490 | - EE_Error::add_error( sprintf(__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", "event_espresso")), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 487 | + }elseif ( ! empty($this->_req_data['QST_ID'])) { |
|
| 488 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
| 489 | + } else { |
|
| 490 | + EE_Error::add_error(sprintf(__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
| 491 | 491 | } |
| 492 | 492 | return $success; |
| 493 | 493 | } |
@@ -498,11 +498,11 @@ discard block |
||
| 498 | 498 | * @param EEM_Soft_Delete_Base $model |
| 499 | 499 | * @return boolean |
| 500 | 500 | */ |
| 501 | - protected function _delete_item( $id, $model ) { |
|
| 502 | - if( $model instanceof EEM_Question ) { |
|
| 503 | - EEM_Question_Option::instance()->delete_permanently( array( array( 'QST_ID' => absint( $id ) ) ) ); |
|
| 501 | + protected function _delete_item($id, $model) { |
|
| 502 | + if ($model instanceof EEM_Question) { |
|
| 503 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
| 504 | 504 | } |
| 505 | - return $model->delete_permanently_by_ID( absint( $id ) ); |
|
| 505 | + return $model->delete_permanently_by_ID(absint($id)); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | |
@@ -514,29 +514,29 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | |
| 516 | 516 | |
| 517 | - protected function _edit_question_group( $type = 'add' ) { |
|
| 518 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 519 | - $ID=isset( $this->_req_data['QSG_ID'] ) && ! empty( $this->_req_data['QSG_ID'] ) ? absint( $this->_req_data['QSG_ID'] ) : FALSE; |
|
| 520 | - $this->_admin_page_title = ucwords( str_replace( '_', ' ', $this->_req_action )); |
|
| 517 | + protected function _edit_question_group($type = 'add') { |
|
| 518 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 519 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : FALSE; |
|
| 520 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 521 | 521 | // add ID to title if editing |
| 522 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 523 | - if($ID){ |
|
| 524 | - $questionGroup=$this->_question_group_model->get_one_by_ID($ID); |
|
| 525 | - $additional_hidden_fields=array('QSG_ID'=>array('type'=>'hidden','value'=>$ID)); |
|
| 522 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
| 523 | + if ($ID) { |
|
| 524 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
| 525 | + $additional_hidden_fields = array('QSG_ID'=>array('type'=>'hidden', 'value'=>$ID)); |
|
| 526 | 526 | $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
| 527 | - }else{ |
|
| 527 | + } else { |
|
| 528 | 528 | $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
| 529 | 529 | $questionGroup->set_order_to_latest(); |
| 530 | 530 | $this->_set_add_edit_form_tags('insert_question_group'); |
| 531 | 531 | } |
| 532 | 532 | $this->_template_args['values'] = $this->_yes_no_values; |
| 533 | - $this->_template_args['all_questions']=$questionGroup->questions_in_and_not_in_group(); |
|
| 534 | - $this->_template_args['QSG_ID']=$ID ? $ID : TRUE; |
|
| 535 | - $this->_template_args['question_group']=$questionGroup; |
|
| 533 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
| 534 | + $this->_template_args['QSG_ID'] = $ID ? $ID : TRUE; |
|
| 535 | + $this->_template_args['question_group'] = $questionGroup; |
|
| 536 | 536 | |
| 537 | - $redirect_URL = add_query_arg( array( 'action' => 'question_groups'), $this->_admin_base_url ); |
|
| 538 | - $this->_set_publish_post_box_vars( 'id', $ID, FALSE, $redirect_URL ); |
|
| 539 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', $this->_template_args, TRUE ); |
|
| 537 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
| 538 | + $this->_set_publish_post_box_vars('id', $ID, FALSE, $redirect_URL); |
|
| 539 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH.'question_groups_main_meta_box.template.php', $this->_template_args, TRUE); |
|
| 540 | 540 | |
| 541 | 541 | // the details template wrapper |
| 542 | 542 | $this->display_admin_page_with_sidebar(); |
@@ -547,76 +547,76 @@ discard block |
||
| 547 | 547 | |
| 548 | 548 | protected function _delete_question_groups() { |
| 549 | 549 | $success = $this->_delete_items($this->_question_group_model); |
| 550 | - $this->_redirect_after_action( $success, $this->_question_group_model->item_name($success), 'deleted permanently', array( 'action'=>'question_groups', 'status'=>'trash' )); |
|
| 550 | + $this->_redirect_after_action($success, $this->_question_group_model->item_name($success), 'deleted permanently', array('action'=>'question_groups', 'status'=>'trash')); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
| 554 | 554 | |
| 555 | - protected function _insert_or_update_question_group( $new_question_group = TRUE) { |
|
| 556 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 557 | - $set_column_values=$this->_set_column_values_for($this->_question_group_model); |
|
| 558 | - if ( $new_question_group ){ |
|
| 555 | + protected function _insert_or_update_question_group($new_question_group = TRUE) { |
|
| 556 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 557 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
| 558 | + if ($new_question_group) { |
|
| 559 | 559 | $QSG_ID = $this->_question_group_model->insert($set_column_values); |
| 560 | 560 | $success = $QSG_ID ? 1 : 0; |
| 561 | 561 | } else { |
| 562 | 562 | $QSG_ID = absint($this->_req_data['QSG_ID']); |
| 563 | - unset( $set_column_values[ 'QSG_ID' ] ); |
|
| 564 | - $success= $this->_question_group_model->update( $set_column_values, array( array( 'QSG_ID' => $QSG_ID ))); |
|
| 563 | + unset($set_column_values['QSG_ID']); |
|
| 564 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
| 565 | 565 | } |
| 566 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( EEM_Attendee::system_question_phone ); |
|
| 566 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone); |
|
| 567 | 567 | // update the existing related questions |
| 568 | 568 | // BUT FIRST... delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group) |
| 569 | - if ( isset( $this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ] )) { |
|
| 569 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
| 570 | 570 | // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
| 571 | - EEM_Question_Group_Question::instance()->delete( array( array( 'QST_ID' => $phone_question_id, 'QSG_ID' => array( '!=', $QSG_ID )))); |
|
| 571 | + EEM_Question_Group_Question::instance()->delete(array(array('QST_ID' => $phone_question_id, 'QSG_ID' => array('!=', $QSG_ID)))); |
|
| 572 | 572 | } |
| 573 | 573 | /** @type EE_Question_Group $question_group */ |
| 574 | - $question_group=$this->_question_group_model->get_one_by_ID( $QSG_ID ); |
|
| 574 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
| 575 | 575 | $questions = $question_group->questions(); |
| 576 | 576 | // make sure system phone question is added to list of questions for this group |
| 577 | - if ( ! isset( $questions[$phone_question_id ] )) { |
|
| 578 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID( $phone_question_id ); |
|
| 577 | + if ( ! isset($questions[$phone_question_id])) { |
|
| 578 | + $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - foreach( $questions as $question_ID => $question ){ |
|
| 581 | + foreach ($questions as $question_ID => $question) { |
|
| 582 | 582 | // first we always check for order. |
| 583 | - if ( ! empty( $this->_req_data['question_orders'][ $question_ID ] ) ){ |
|
| 583 | + if ( ! empty($this->_req_data['question_orders'][$question_ID])) { |
|
| 584 | 584 | //update question order |
| 585 | - $question_group->update_question_order( $question_ID, $this->_req_data['question_orders'][ $question_ID ] ); |
|
| 585 | + $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | // then we always check if adding or removing. |
| 589 | - if ( isset( $this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ] )) { |
|
| 590 | - $question_group->add_question( $question_ID ); |
|
| 589 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
| 590 | + $question_group->add_question($question_ID); |
|
| 591 | 591 | } else { |
| 592 | 592 | // not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it) |
| 593 | 593 | if ( |
| 594 | 594 | in_array( |
| 595 | 595 | $question->system_ID(), |
| 596 | - EEM_Question::instance()->required_system_questions_in_system_question_group( $question_group->system_group() ) |
|
| 596 | + EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group()) |
|
| 597 | 597 | ) |
| 598 | 598 | ) { |
| 599 | 599 | continue; |
| 600 | 600 | } else { |
| 601 | - $question_group->remove_question( $question_ID ); |
|
| 601 | + $question_group->remove_question($question_ID); |
|
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | // save new related questions |
| 606 | - if ( isset( $this->_req_data['questions'] )) { |
|
| 607 | - foreach( $this->_req_data['questions'] as $QST_ID ){ |
|
| 608 | - $question_group->add_question( $QST_ID ); |
|
| 609 | - if ( isset( $this->_req_data['question_orders'][ $QST_ID ] )) { |
|
| 610 | - $question_group->update_question_order( $QST_ID, $this->_req_data['question_orders'][ $QST_ID ] ); |
|
| 606 | + if (isset($this->_req_data['questions'])) { |
|
| 607 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
| 608 | + $question_group->add_question($QST_ID); |
|
| 609 | + if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
| 610 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
| 611 | 611 | } |
| 612 | 612 | } |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - if ( $success !== FALSE ) { |
|
| 616 | - $msg = $new_question_group ? sprintf( __('The %s has been created', 'event_espresso'), $this->_question_group_model->item_name() ) : sprintf( __('The %s has been updated', 'event_espresso' ), $this->_question_group_model->item_name() ); |
|
| 617 | - EE_Error::add_success( $msg ); |
|
| 615 | + if ($success !== FALSE) { |
|
| 616 | + $msg = $new_question_group ? sprintf(__('The %s has been created', 'event_espresso'), $this->_question_group_model->item_name()) : sprintf(__('The %s has been updated', 'event_espresso'), $this->_question_group_model->item_name()); |
|
| 617 | + EE_Error::add_success($msg); |
|
| 618 | 618 | } |
| 619 | - $this->_redirect_after_action(FALSE, '', '', array('action'=>'edit_question_group','QSG_ID'=>$QSG_ID), TRUE); |
|
| 619 | + $this->_redirect_after_action(FALSE, '', '', array('action'=>'edit_question_group', 'QSG_ID'=>$QSG_ID), TRUE); |
|
| 620 | 620 | |
| 621 | 621 | } |
| 622 | 622 | |
@@ -624,39 +624,39 @@ discard block |
||
| 624 | 624 | * duplicates a question and all its question options and redirects to the new question. |
| 625 | 625 | */ |
| 626 | 626 | public function _duplicate_question() { |
| 627 | - $question_ID = intval( $this->_req_data[ 'QST_ID' ] ); |
|
| 628 | - $question = EEM_Question::instance()->get_one_by_ID( $question_ID ); |
|
| 629 | - if( $question instanceof EE_Question ) { |
|
| 627 | + $question_ID = intval($this->_req_data['QST_ID']); |
|
| 628 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
| 629 | + if ($question instanceof EE_Question) { |
|
| 630 | 630 | $new_question = $question->duplicate(); |
| 631 | - if( $new_question instanceof EE_Question ) { |
|
| 632 | - $this->_redirect_after_action( true, __( 'Question', 'event_espresso' ), __( 'Duplicated', 'event_espresso' ), array('action'=>'edit_question', 'QST_ID' => $new_question->ID() ), TRUE); |
|
| 631 | + if ($new_question instanceof EE_Question) { |
|
| 632 | + $this->_redirect_after_action(true, __('Question', 'event_espresso'), __('Duplicated', 'event_espresso'), array('action'=>'edit_question', 'QST_ID' => $new_question->ID()), TRUE); |
|
| 633 | 633 | } else { |
| 634 | 634 | global $wpdb; |
| 635 | - EE_Error::add_error( sprintf( __( 'Could not duplicate question with ID %1$d because: %2$s', 'event_espresso' ), $question_ID, $wpdb->last_error ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 636 | - $this->_redirect_after_action(false, '', '', array('action'=>'default'), false ); |
|
| 635 | + EE_Error::add_error(sprintf(__('Could not duplicate question with ID %1$d because: %2$s', 'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__); |
|
| 636 | + $this->_redirect_after_action(false, '', '', array('action'=>'default'), false); |
|
| 637 | 637 | } |
| 638 | 638 | } else { |
| 639 | - EE_Error::add_error( sprintf( __( 'Could not duplicate question with ID %d because it didn\'t exist!', 'event_espresso' ), $question_ID ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 640 | - $this->_redirect_after_action( false, '', '', array( 'action' => 'default' ), false ); |
|
| 639 | + EE_Error::add_error(sprintf(__('Could not duplicate question with ID %d because it didn\'t exist!', 'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__); |
|
| 640 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | |
| 645 | 645 | |
| 646 | 646 | protected function _trash_or_restore_question_groups($trash = TRUE) { |
| 647 | - return $this->_trash_or_restore_items( $this->_question_group_model, $trash ); |
|
| 647 | + return $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - protected function _trash_question(){ |
|
| 651 | - $success=$this->_question_model->delete_by_ID(intval($this->_req_data['QST_ID'])); |
|
| 652 | - $query_args=array('action'=>'default','status'=>'all'); |
|
| 650 | + protected function _trash_question() { |
|
| 651 | + $success = $this->_question_model->delete_by_ID(intval($this->_req_data['QST_ID'])); |
|
| 652 | + $query_args = array('action'=>'default', 'status'=>'all'); |
|
| 653 | 653 | $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | |
| 657 | 657 | |
| 658 | - protected function _trash_or_restore_questions($trash=TRUE){ |
|
| 659 | - $this->_trash_or_restore_items( $this->_question_model, $trash ); |
|
| 658 | + protected function _trash_or_restore_questions($trash = TRUE) { |
|
| 659 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | |
@@ -667,21 +667,21 @@ discard block |
||
| 667 | 667 | * @param EEM_Base $model |
| 668 | 668 | * @param boolean $trash wehter to trash or restore |
| 669 | 669 | */ |
| 670 | - private function _trash_or_restore_items( EEM_Base $model, $trash = TRUE ) { |
|
| 670 | + private function _trash_or_restore_items(EEM_Base $model, $trash = TRUE) { |
|
| 671 | 671 | |
| 672 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 672 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 673 | 673 | |
| 674 | 674 | $success = 1; |
| 675 | 675 | //Checkboxes |
| 676 | 676 | //echo "trash $trash"; |
| 677 | 677 | //var_dump($this->_req_data['checkbox']);die; |
| 678 | - if ( isset( $this->_req_data['checkbox'] )) { |
|
| 679 | - if ( isset( $this->_req_data['checkbox'] ) && ! empty( $this->_req_data['checkbox'] ) && is_array( $this->_req_data['checkbox'] )) { |
|
| 678 | + if (isset($this->_req_data['checkbox'])) { |
|
| 679 | + if (isset($this->_req_data['checkbox']) && ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 680 | 680 | // if array has more than one element than success message should be plural |
| 681 | - $success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1; |
|
| 681 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 682 | 682 | // cycle thru bulk action checkboxes |
| 683 | - while (list( $ID, $value ) = each($this->_req_data['checkbox'])) { |
|
| 684 | - if ( ! $model->delete_or_restore_by_ID($trash,absint($ID))) { |
|
| 683 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 684 | + if ( ! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 685 | 685 | $success = 0; |
| 686 | 686 | } |
| 687 | 687 | } |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | } else { |
| 690 | 690 | // grab single id and delete |
| 691 | 691 | $ID = absint($this->_req_data['checkbox']); |
| 692 | - if ( ! $model->delete_or_restore_by_ID($trash,$ID)) { |
|
| 692 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 693 | 693 | $success = 0; |
| 694 | 694 | } |
| 695 | 695 | } |
@@ -697,53 +697,53 @@ discard block |
||
| 697 | 697 | } else { |
| 698 | 698 | // delete via trash link |
| 699 | 699 | // grab single id and delete |
| 700 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
| 701 | - if ( ! $model->delete_or_restore_by_ID($trash,$ID)) { |
|
| 700 | + $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
| 701 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 702 | 702 | $success = 0; |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | |
| 708 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
| 708 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups'; //strtolower( $model->item_name(2) ); |
|
| 709 | 709 | //echo "action :$action"; |
| 710 | 710 | //$action = 'questions' ? 'default' : $action; |
| 711 | - if($trash){ |
|
| 711 | + if ($trash) { |
|
| 712 | 712 | $action_desc = 'trashed'; |
| 713 | 713 | $status = 'trash'; |
| 714 | - }else{ |
|
| 714 | + } else { |
|
| 715 | 715 | $action_desc = 'restored'; |
| 716 | 716 | $status = 'all'; |
| 717 | 717 | } |
| 718 | - $this->_redirect_after_action( $success, $model->item_name($success), $action_desc, array( 'action' => $action, 'status'=>$status ) ); |
|
| 718 | + $this->_redirect_after_action($success, $model->item_name($success), $action_desc, array('action' => $action, 'status'=>$status)); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | |
| 722 | 722 | |
| 723 | 723 | |
| 724 | - public function get_trashed_questions( $per_page,$current_page = 1, $count = FALSE ) { |
|
| 724 | + public function get_trashed_questions($per_page, $current_page = 1, $count = FALSE) { |
|
| 725 | 725 | $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
| 726 | 726 | |
| 727 | - if( $count ){ |
|
| 727 | + if ($count) { |
|
| 728 | 728 | //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
| 729 | - $where = isset( $query_params[0] ) ? array( $query_params[0] ) : array(); |
|
| 730 | - $results=$this->_question_model->count_deleted($where); |
|
| 731 | - }else{ |
|
| 729 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 730 | + $results = $this->_question_model->count_deleted($where); |
|
| 731 | + } else { |
|
| 732 | 732 | //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
| 733 | - $results=$this->_question_model->get_all_deleted($query_params); |
|
| 733 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
| 734 | 734 | } |
| 735 | 735 | return $results; |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | |
| 740 | - public function get_question_groups( $per_page, $current_page = 1, $count = FALSE ) { |
|
| 741 | - $questionGroupModel=EEM_Question_Group::instance(); |
|
| 742 | - $query_params=$this->get_query_params($questionGroupModel,$per_page,$current_page); |
|
| 743 | - if ($count){ |
|
| 744 | - $where = isset( $query_params[0] ) ? array( $query_params[0] ) : array(); |
|
| 740 | + public function get_question_groups($per_page, $current_page = 1, $count = FALSE) { |
|
| 741 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 742 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 743 | + if ($count) { |
|
| 744 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 745 | 745 | $results = $questionGroupModel->count($where); |
| 746 | - }else{ |
|
| 746 | + } else { |
|
| 747 | 747 | $results = $questionGroupModel->get_all($query_params); |
| 748 | 748 | } |
| 749 | 749 | return $results; |
@@ -751,14 +751,14 @@ discard block |
||
| 751 | 751 | |
| 752 | 752 | |
| 753 | 753 | |
| 754 | - public function get_trashed_question_groups( $per_page,$current_page = 1, $count = FALSE ) { |
|
| 755 | - $questionGroupModel=EEM_Question_Group::instance(); |
|
| 756 | - $query_params=$this->get_query_params($questionGroupModel,$per_page,$current_page); |
|
| 757 | - if($count){ |
|
| 758 | - $where = isset( $query_params[0] ) ? array($query_params[0]) : array(); |
|
| 754 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = FALSE) { |
|
| 755 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 756 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 757 | + if ($count) { |
|
| 758 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 759 | 759 | $query_params['limit'] = NULL; |
| 760 | 760 | $results = $questionGroupModel->count_deleted($where); |
| 761 | - }else{ |
|
| 761 | + } else { |
|
| 762 | 762 | $results = $questionGroupModel->get_all_deleted($query_params); |
| 763 | 763 | } |
| 764 | 764 | return $results; |
@@ -771,22 +771,22 @@ discard block |
||
| 771 | 771 | */ |
| 772 | 772 | public function update_question_group_order() { |
| 773 | 773 | |
| 774 | - $success = __( 'Question group order was updated successfully.', 'event_espresso' ); |
|
| 774 | + $success = __('Question group order was updated successfully.', 'event_espresso'); |
|
| 775 | 775 | |
| 776 | 776 | // grab our row IDs |
| 777 | - $row_ids = isset( $this->_req_data['row_ids'] ) && ! empty( $this->_req_data['row_ids'] ) ? explode( ',', rtrim( $this->_req_data['row_ids'], ',' )) : FALSE; |
|
| 777 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode(',', rtrim($this->_req_data['row_ids'], ',')) : FALSE; |
|
| 778 | 778 | |
| 779 | - $perpage = !empty( $this->_req_data['perpage'] ) ? (int) $this->_req_data['perpage'] : NULL; |
|
| 780 | - $curpage = !empty( $this->_req_data['curpage'] ) ? (int) $this->_req_data['curpage'] : NULL; |
|
| 779 | + $perpage = ! empty($this->_req_data['perpage']) ? (int) $this->_req_data['perpage'] : NULL; |
|
| 780 | + $curpage = ! empty($this->_req_data['curpage']) ? (int) $this->_req_data['curpage'] : NULL; |
|
| 781 | 781 | |
| 782 | - if ( is_array( $row_ids )) { |
|
| 782 | + if (is_array($row_ids)) { |
|
| 783 | 783 | //figure out where we start the row_id count at for the current page. |
| 784 | - $qsgcount = empty( $curpage ) ? 0 : ($curpage - 1 ) * $perpage; |
|
| 784 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
| 785 | 785 | |
| 786 | 786 | global $wpdb; |
| 787 | - for ( $i = 0; $i < count($row_ids); $i++ ) { |
|
| 787 | + for ($i = 0; $i < count($row_ids); $i++) { |
|
| 788 | 788 | //Update the questions when re-ordering |
| 789 | - if ( EEM_Question_Group::instance()->update ( array( 'QSG_order' => $qsgcount ), array(array( 'QSG_ID' => $row_ids[$i] ))) === FALSE ) { |
|
| 789 | + if (EEM_Question_Group::instance()->update(array('QSG_order' => $qsgcount), array(array('QSG_ID' => $row_ids[$i]))) === FALSE) { |
|
| 790 | 790 | $success = FALSE; |
| 791 | 791 | } |
| 792 | 792 | $qsgcount++; |
@@ -795,9 +795,9 @@ discard block |
||
| 795 | 795 | $success = FALSE; |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | - $errors = ! $success ? __( 'An error occurred. The question group order was not updated.', 'event_espresso' ) : FALSE; |
|
| 798 | + $errors = ! $success ? __('An error occurred. The question group order was not updated.', 'event_espresso') : FALSE; |
|
| 799 | 799 | |
| 800 | - echo json_encode( array( 'return_data' => FALSE, 'success' => $success, 'errors' => $errors )); |
|
| 800 | + echo json_encode(array('return_data' => FALSE, 'success' => $success, 'errors' => $errors)); |
|
| 801 | 801 | die(); |
| 802 | 802 | |
| 803 | 803 | } |
@@ -814,10 +814,10 @@ discard block |
||
| 814 | 814 | |
| 815 | 815 | protected function _reg_form_settings() { |
| 816 | 816 | $this->_template_args['values'] = $this->_yes_no_values; |
| 817 | - $this->_template_args = apply_filters( 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', $this->_template_args ); |
|
| 818 | - $this->_set_add_edit_form_tags( 'update_reg_form_settings' ); |
|
| 819 | - $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 820 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', $this->_template_args, TRUE ); |
|
| 817 | + $this->_template_args = apply_filters('FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', $this->_template_args); |
|
| 818 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 819 | + $this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE); |
|
| 820 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH.'reg_form_settings.template.php', $this->_template_args, TRUE); |
|
| 821 | 821 | $this->display_admin_page_with_sidebar(); |
| 822 | 822 | } |
| 823 | 823 | |
@@ -825,9 +825,9 @@ discard block |
||
| 825 | 825 | |
| 826 | 826 | |
| 827 | 827 | protected function _update_reg_form_settings() { |
| 828 | - EE_Registry::instance()->CFG->registration = apply_filters( 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', EE_Registry::instance()->CFG->registration ); |
|
| 829 | - $success = $this->_update_espresso_configuration( __('Registration Form Options', 'event_espresso'), EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 830 | - $this->_redirect_after_action( $success, __('Registration Form Options', 'event_espresso'), 'updated', array( 'action' => 'view_reg_form_settings' ) ); |
|
| 828 | + EE_Registry::instance()->CFG->registration = apply_filters('FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', EE_Registry::instance()->CFG->registration); |
|
| 829 | + $success = $this->_update_espresso_configuration(__('Registration Form Options', 'event_espresso'), EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, __LINE__); |
|
| 830 | + $this->_redirect_after_action($success, __('Registration Form Options', 'event_espresso'), 'updated', array('action' => 'view_reg_form_settings')); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
| 45 | 45 | * @return \Payments_Admin_Page |
| 46 | 46 | */ |
| 47 | - public function __construct( $routing = TRUE ) { |
|
| 48 | - parent::__construct( $routing ); |
|
| 47 | + public function __construct($routing = TRUE) { |
|
| 48 | + parent::__construct($routing); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | |
@@ -130,19 +130,19 @@ discard block |
||
| 130 | 130 | protected function _set_page_config() { |
| 131 | 131 | $payment_method_list_config = array( |
| 132 | 132 | 'nav' => array( |
| 133 | - 'label' => __( 'Payment Methods', 'event_espresso' ), |
|
| 133 | + 'label' => __('Payment Methods', 'event_espresso'), |
|
| 134 | 134 | 'order' => 10 |
| 135 | 135 | ), |
| 136 | 136 | 'metaboxes' => $this->_default_espresso_metaboxes, |
| 137 | 137 | 'help_tabs' => array_merge( |
| 138 | 138 | array( |
| 139 | 139 | 'payment_methods_overview_help_tab' => array( |
| 140 | - 'title' => __( 'Payment Methods Overview', 'event_espresso' ), |
|
| 140 | + 'title' => __('Payment Methods Overview', 'event_espresso'), |
|
| 141 | 141 | 'filename' => 'payment_methods_overview' |
| 142 | 142 | ) |
| 143 | 143 | ), |
| 144 | 144 | $this->_add_payment_method_help_tabs() ), |
| 145 | - 'help_tour' => array( 'Payment_Methods_Selection_Help_Tour' ), |
|
| 145 | + 'help_tour' => array('Payment_Methods_Selection_Help_Tour'), |
|
| 146 | 146 | 'require_nonce' => false |
| 147 | 147 | ); |
| 148 | 148 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | ) |
| 161 | 161 | ), |
| 162 | 162 | //'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ), |
| 163 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_publish_post_box' ) ), |
|
| 163 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 164 | 164 | 'require_nonce' => FALSE |
| 165 | 165 | ), |
| 166 | 166 | 'payment_log'=>array( |
@@ -179,17 +179,17 @@ discard block |
||
| 179 | 179 | /** |
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | - protected function _add_payment_method_help_tabs(){ |
|
| 182 | + protected function _add_payment_method_help_tabs() { |
|
| 183 | 183 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
| 184 | 184 | $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types(); |
| 185 | 185 | $all_pmt_help_tabs_config = array(); |
| 186 | - foreach( $payment_method_types as $payment_method_type ){ |
|
| 187 | - if ( ! EE_Registry::instance()->CAP->current_user_can( $payment_method_type->cap_name(), 'specific_payment_method_type_access' ) ) { |
|
| 186 | + foreach ($payment_method_types as $payment_method_type) { |
|
| 187 | + if ( ! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), 'specific_payment_method_type_access')) { |
|
| 188 | 188 | continue; |
| 189 | 189 | } |
| 190 | - foreach( $payment_method_type->help_tabs_config() as $help_tab_name => $config ){ |
|
| 191 | - $template_args = isset( $config[ 'template_args' ] ) ? $config[ 'template_args' ] : array(); |
|
| 192 | - $template_args[ 'admin_page_obj' ] = $this; |
|
| 190 | + foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) { |
|
| 191 | + $template_args = isset($config['template_args']) ? $config['template_args'] : array(); |
|
| 192 | + $template_args['admin_page_obj'] = $this; |
|
| 193 | 193 | $all_pmt_help_tabs_config[$help_tab_name] = array( |
| 194 | 194 | 'title'=>$config['title'], |
| 195 | 195 | 'content'=>EEH_Template::display_template( |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | |
| 218 | 218 | public function load_scripts_styles() { |
| 219 | - wp_enqueue_script( 'ee_admin_js' ); |
|
| 220 | - wp_enqueue_script( 'ee-text-links' ); |
|
| 221 | - wp_enqueue_script( 'espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', array( 'espresso-ui-theme', 'ee-datepicker' ), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 219 | + wp_enqueue_script('ee_admin_js'); |
|
| 220 | + wp_enqueue_script('ee-text-links'); |
|
| 221 | + wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js', array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | |
@@ -227,9 +227,9 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | public function load_scripts_styles_default() { |
| 229 | 229 | //styles |
| 230 | - wp_register_style( 'espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 231 | - wp_enqueue_style( 'espresso_payments' ); |
|
| 232 | - wp_enqueue_style( 'ee-text-links' ); |
|
| 230 | + wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL.'ee-payments.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 231 | + wp_enqueue_style('espresso_payments'); |
|
| 232 | + wp_enqueue_style('ee-text-links'); |
|
| 233 | 233 | //scripts |
| 234 | 234 | } |
| 235 | 235 | |
@@ -243,46 +243,46 @@ discard block |
||
| 243 | 243 | * to the loading process. However, people MUST setup the details for the payment method so its safe to do a |
| 244 | 244 | * recheck here. |
| 245 | 245 | */ |
| 246 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
| 246 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 247 | 247 | EEM_Payment_Method::instance()->verify_button_urls(); |
| 248 | - EE_Registry::instance()->load_helper( 'Tabbed_Content' ); |
|
| 249 | - EE_Registry::instance()->load_helper( 'HTML' ); |
|
| 248 | + EE_Registry::instance()->load_helper('Tabbed_Content'); |
|
| 249 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 250 | 250 | //setup tabs, one for each payment method type |
| 251 | 251 | $tabs = array(); |
| 252 | 252 | $payment_methods = array(); |
| 253 | - foreach( EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj ) { |
|
| 253 | + foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { |
|
| 254 | 254 | // we don't want to show admin-only PMTs for now |
| 255 | - if ( $pmt_obj instanceof EE_PMT_Admin_Only ) { |
|
| 255 | + if ($pmt_obj instanceof EE_PMT_Admin_Only) { |
|
| 256 | 256 | continue; |
| 257 | 257 | } |
| 258 | 258 | //check access |
| 259 | - if ( ! EE_Registry::instance()->CAP->current_user_can( $pmt_obj->cap_name(), 'specific_payment_method_type_access' ) ) { |
|
| 259 | + if ( ! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), 'specific_payment_method_type_access')) { |
|
| 260 | 260 | continue; |
| 261 | 261 | } |
| 262 | 262 | //check for any active pms of that type |
| 263 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type( $pmt_obj->system_name() ); |
|
| 264 | - if ( ! $payment_method instanceof EE_Payment_Method ) { |
|
| 263 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
|
| 264 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 265 | 265 | $payment_method = EE_Payment_Method::new_instance( |
| 266 | 266 | array( |
| 267 | - 'PMD_slug' =>sanitize_key( $pmt_obj->system_name() ), |
|
| 267 | + 'PMD_slug' =>sanitize_key($pmt_obj->system_name()), |
|
| 268 | 268 | 'PMD_type' =>$pmt_obj->system_name(), |
| 269 | 269 | 'PMD_name' =>$pmt_obj->pretty_name(), |
| 270 | 270 | 'PMD_admin_name' =>$pmt_obj->pretty_name() |
| 271 | 271 | ) |
| 272 | 272 | ); |
| 273 | 273 | } |
| 274 | - $payment_methods[ $payment_method->slug() ] = $payment_method; |
|
| 274 | + $payment_methods[$payment_method->slug()] = $payment_method; |
|
| 275 | 275 | } |
| 276 | - $payment_methods = apply_filters( 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', $payment_methods ); |
|
| 277 | - foreach( $payment_methods as $payment_method ) { |
|
| 278 | - if ( $payment_method instanceof EE_Payment_Method ) { |
|
| 276 | + $payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', $payment_methods); |
|
| 277 | + foreach ($payment_methods as $payment_method) { |
|
| 278 | + if ($payment_method instanceof EE_Payment_Method) { |
|
| 279 | 279 | add_meta_box( |
| 280 | 280 | //html id |
| 281 | - 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
| 281 | + 'espresso_'.$payment_method->slug().'_payment_settings', |
|
| 282 | 282 | //title |
| 283 | - sprintf( __( '%s Settings', 'event_espresso' ), $payment_method->admin_name() ), |
|
| 283 | + sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
|
| 284 | 284 | //callback |
| 285 | - array( $this, 'payment_method_settings_meta_box' ), |
|
| 285 | + array($this, 'payment_method_settings_meta_box'), |
|
| 286 | 286 | //post type |
| 287 | 287 | null, |
| 288 | 288 | //context |
@@ -290,19 +290,19 @@ discard block |
||
| 290 | 290 | //priority |
| 291 | 291 | 'default', |
| 292 | 292 | //callback args |
| 293 | - array( 'payment_method' => $payment_method ) |
|
| 293 | + array('payment_method' => $payment_method) |
|
| 294 | 294 | ); |
| 295 | 295 | //setup for tabbed content |
| 296 | - $tabs[ $payment_method->slug() ] = array( |
|
| 296 | + $tabs[$payment_method->slug()] = array( |
|
| 297 | 297 | 'label' => $payment_method->admin_name(), |
| 298 | 298 | 'class' => $payment_method->active() ? 'gateway-active' : '', |
| 299 | - 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
| 300 | - 'title' => __( 'Modify this Payment Method', 'event_espresso' ), |
|
| 299 | + 'href' => 'espresso_'.$payment_method->slug().'_payment_settings', |
|
| 300 | + 'title' => __('Modify this Payment Method', 'event_espresso'), |
|
| 301 | 301 | 'slug' => $payment_method->slug() |
| 302 | 302 | ); |
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( $tabs, 'payment_method_links', '|', $this->_get_active_payment_method_slug() ); |
|
| 305 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links', '|', $this->_get_active_payment_method_slug()); |
|
| 306 | 306 | $this->display_admin_page_with_sidebar(); |
| 307 | 307 | |
| 308 | 308 | } |
@@ -313,20 +313,20 @@ discard block |
||
| 313 | 313 | * _get_active_payment_method_slug |
| 314 | 314 | * @return string |
| 315 | 315 | */ |
| 316 | - protected function _get_active_payment_method_slug(){ |
|
| 316 | + protected function _get_active_payment_method_slug() { |
|
| 317 | 317 | $payment_method_slug = FALSE; |
| 318 | 318 | //decide which payment method tab to open first, as dictated by the request's 'payment_method' |
| 319 | - if ( isset( $this->_req_data['payment_method'] )) { |
|
| 319 | + if (isset($this->_req_data['payment_method'])) { |
|
| 320 | 320 | // if they provided the current payment method, use it |
| 321 | - $payment_method_slug = sanitize_key( $this->_req_data['payment_method'] ); |
|
| 321 | + $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
| 322 | 322 | } |
| 323 | - $payment_method = EEM_Payment_Method::instance()->get_one( array( array( 'PMD_slug' => $payment_method_slug ))); |
|
| 323 | + $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
|
| 324 | 324 | // if that didn't work or wasn't provided, find another way to select the current pm |
| 325 | - if ( ! $this->_verify_payment_method( $payment_method )) { |
|
| 325 | + if ( ! $this->_verify_payment_method($payment_method)) { |
|
| 326 | 326 | // like, looking for an active one |
| 327 | - $payment_method = EEM_Payment_Method::instance()->get_one_active( 'CART' ); |
|
| 327 | + $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
|
| 328 | 328 | // test that one as well |
| 329 | - if ( $this->_verify_payment_method( $payment_method )) { |
|
| 329 | + if ($this->_verify_payment_method($payment_method)) { |
|
| 330 | 330 | $payment_method_slug = $payment_method->slug(); |
| 331 | 331 | } else { |
| 332 | 332 | $payment_method_slug = 'paypal_standard'; |
@@ -344,11 +344,11 @@ discard block |
||
| 344 | 344 | * @param \EE_Payment_Method $payment_method |
| 345 | 345 | * @return boolean |
| 346 | 346 | */ |
| 347 | - protected function _verify_payment_method( $payment_method ){ |
|
| 347 | + protected function _verify_payment_method($payment_method) { |
|
| 348 | 348 | if ( |
| 349 | 349 | $payment_method instanceof EE_Payment_Method && |
| 350 | 350 | $payment_method->type_obj() instanceof EE_PMT_Base && |
| 351 | - EE_Registry::instance()->CAP->current_user_can( $payment_method->type_obj()->cap_name(), 'specific_payment_method_type_access' ) |
|
| 351 | + EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(), 'specific_payment_method_type_access') |
|
| 352 | 352 | ) { |
| 353 | 353 | return TRUE; |
| 354 | 354 | } |
@@ -365,21 +365,21 @@ discard block |
||
| 365 | 365 | * @return string |
| 366 | 366 | * @throws EE_Error |
| 367 | 367 | */ |
| 368 | - public function payment_method_settings_meta_box( $post_obj_which_is_null, $metabox ){ |
|
| 369 | - $payment_method = isset( $metabox['args'], $metabox['args']['payment_method'] ) ? $metabox['args']['payment_method'] : NULL; |
|
| 370 | - if ( ! $payment_method instanceof EE_Payment_Method ){ |
|
| 371 | - throw new EE_Error( sprintf( __( 'Payment method metabox setup incorrectly. No Payment method object was supplied', 'event_espresso' ))); |
|
| 368 | + public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox) { |
|
| 369 | + $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) ? $metabox['args']['payment_method'] : NULL; |
|
| 370 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 371 | + throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied', 'event_espresso'))); |
|
| 372 | 372 | } |
| 373 | 373 | $payment_method_scopes = $payment_method->active(); |
| 374 | 374 | // if the payment method really exists show its form, otherwise the activation template |
| 375 | - if ( $payment_method->ID() && ! empty( $payment_method_scopes )) { |
|
| 376 | - $form = $this->_generate_payment_method_settings_form( $payment_method ); |
|
| 377 | - if ( $form->form_data_present_in( $this->_req_data )) { |
|
| 378 | - $form->receive_form_submission( $this->_req_data ); |
|
| 375 | + if ($payment_method->ID() && ! empty($payment_method_scopes)) { |
|
| 376 | + $form = $this->_generate_payment_method_settings_form($payment_method); |
|
| 377 | + if ($form->form_data_present_in($this->_req_data)) { |
|
| 378 | + $form->receive_form_submission($this->_req_data); |
|
| 379 | 379 | } |
| 380 | - echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
| 380 | + echo $form->form_open().$form->get_html_and_js().$form->form_close(); |
|
| 381 | 381 | } else { |
| 382 | - echo $this->_activate_payment_method_button( $payment_method )->get_html_and_js(); |
|
| 382 | + echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | |
@@ -392,14 +392,14 @@ discard block |
||
| 392 | 392 | * @param \EE_Payment_Method $payment_method |
| 393 | 393 | * @return \EE_Form_Section_Proper |
| 394 | 394 | */ |
| 395 | - protected function _generate_payment_method_settings_form( EE_Payment_Method $payment_method ) { |
|
| 396 | - if ( ! $payment_method instanceof EE_Payment_Method ){ |
|
| 395 | + protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) { |
|
| 396 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 397 | 397 | return new EE_Form_Section_Proper(); |
| 398 | 398 | } |
| 399 | 399 | return new EE_Form_Section_Proper( |
| 400 | 400 | array( |
| 401 | - 'name' => $payment_method->slug() . '_settings_form', |
|
| 402 | - 'html_id' => $payment_method->slug() . '_settings_form', |
|
| 401 | + 'name' => $payment_method->slug().'_settings_form', |
|
| 402 | + 'html_id' => $payment_method->slug().'_settings_form', |
|
| 403 | 403 | 'action' => EE_Admin_Page::add_query_args_and_nonce( |
| 404 | 404 | array( |
| 405 | 405 | 'action' => 'update_payment_method', |
@@ -411,12 +411,12 @@ discard block |
||
| 411 | 411 | 'subsections' => apply_filters( |
| 412 | 412 | 'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections', |
| 413 | 413 | array( |
| 414 | - 'pci_dss_compliance_' . $payment_method->slug() => $this->_pci_dss_compliance( $payment_method ), |
|
| 415 | - 'currency_support_' . $payment_method->slug() => $this->_currency_support( $payment_method ), |
|
| 416 | - 'payment_method_settings_' . $payment_method->slug() => $this->_payment_method_settings( $payment_method ), |
|
| 417 | - 'update_' . $payment_method->slug() => $this->_update_payment_method_button( $payment_method ), |
|
| 418 | - 'deactivate_' . $payment_method->slug() => $this->_deactivate_payment_method_button( $payment_method ), |
|
| 419 | - 'fine_print_' . $payment_method->slug() => $this->_fine_print() |
|
| 414 | + 'pci_dss_compliance_'.$payment_method->slug() => $this->_pci_dss_compliance($payment_method), |
|
| 415 | + 'currency_support_'.$payment_method->slug() => $this->_currency_support($payment_method), |
|
| 416 | + 'payment_method_settings_'.$payment_method->slug() => $this->_payment_method_settings($payment_method), |
|
| 417 | + 'update_'.$payment_method->slug() => $this->_update_payment_method_button($payment_method), |
|
| 418 | + 'deactivate_'.$payment_method->slug() => $this->_deactivate_payment_method_button($payment_method), |
|
| 419 | + 'fine_print_'.$payment_method->slug() => $this->_fine_print() |
|
| 420 | 420 | ), |
| 421 | 421 | $payment_method |
| 422 | 422 | ) |
@@ -433,19 +433,19 @@ discard block |
||
| 433 | 433 | * @param \EE_Payment_Method $payment_method |
| 434 | 434 | * @return \EE_Form_Section_Proper |
| 435 | 435 | */ |
| 436 | - protected function _pci_dss_compliance( EE_Payment_Method $payment_method ) { |
|
| 437 | - if ( $payment_method->type_obj()->requires_https() ) { |
|
| 436 | + protected function _pci_dss_compliance(EE_Payment_Method $payment_method) { |
|
| 437 | + if ($payment_method->type_obj()->requires_https()) { |
|
| 438 | 438 | return new EE_Form_Section_HTML( |
| 439 | 439 | EEH_HTML::tr( |
| 440 | 440 | EEH_HTML::th( |
| 441 | 441 | EEH_HTML::label( |
| 442 | - EEH_HTML::strong( __( 'IMPORTANT', 'event_espresso' ), '', 'important-notice' ) |
|
| 442 | + EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
| 443 | 443 | ) |
| 444 | - ) . |
|
| 444 | + ). |
|
| 445 | 445 | EEH_HTML::td( |
| 446 | - EEH_HTML::strong( __( 'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', 'event_espresso' )) . |
|
| 447 | - EEH_HTML::br() . |
|
| 448 | - __( 'Learn more about ', 'event_espresso' ) . EEH_HTML::link( 'https://www.pcisecuritystandards.org/merchants/index.php', __( 'PCI DSS compliance', 'event_espresso' )) |
|
| 446 | + EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', 'event_espresso')). |
|
| 447 | + EEH_HTML::br(). |
|
| 448 | + __('Learn more about ', 'event_espresso').EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php', __('PCI DSS compliance', 'event_espresso')) |
|
| 449 | 449 | ) |
| 450 | 450 | ) |
| 451 | 451 | ); |
@@ -463,19 +463,19 @@ discard block |
||
| 463 | 463 | * @param \EE_Payment_Method $payment_method |
| 464 | 464 | * @return \EE_Form_Section_Proper |
| 465 | 465 | */ |
| 466 | - protected function _currency_support( EE_Payment_Method $payment_method ) { |
|
| 467 | - if ( ! $payment_method->usable_for_currency( EE_Config::instance()->currency->code )) { |
|
| 466 | + protected function _currency_support(EE_Payment_Method $payment_method) { |
|
| 467 | + if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
| 468 | 468 | return new EE_Form_Section_HTML( |
| 469 | 469 | EEH_HTML::tr( |
| 470 | 470 | EEH_HTML::th( |
| 471 | 471 | EEH_HTML::label( |
| 472 | - EEH_HTML::strong( __( 'IMPORTANT', 'event_espresso' ), '', 'important-notice' ) |
|
| 472 | + EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
| 473 | 473 | ) |
| 474 | - ) . |
|
| 474 | + ). |
|
| 475 | 475 | EEH_HTML::td( |
| 476 | 476 | EEH_HTML::strong( |
| 477 | 477 | sprintf( |
| 478 | - __( 'This payment method does not support the currency set on your site (%1$s) and so will not appear as a payment option to registrants. Please activate a different payment method or change your site\'s country and associated currency.', 'event_espresso'), |
|
| 478 | + __('This payment method does not support the currency set on your site (%1$s) and so will not appear as a payment option to registrants. Please activate a different payment method or change your site\'s country and associated currency.', 'event_espresso'), |
|
| 479 | 479 | EE_Config::instance()->currency->code |
| 480 | 480 | ) |
| 481 | 481 | ) |
@@ -495,9 +495,9 @@ discard block |
||
| 495 | 495 | * @param \EE_Payment_Method $payment_method |
| 496 | 496 | * @return \EE_Form_Section_HTML |
| 497 | 497 | */ |
| 498 | - protected function _payment_method_settings( EE_Payment_Method $payment_method ) { |
|
| 498 | + protected function _payment_method_settings(EE_Payment_Method $payment_method) { |
|
| 499 | 499 | //modify the form so we only have/show fields that will be implemented for this version |
| 500 | - return $this->_simplify_form( $payment_method->type_obj()->settings_form(), $payment_method->name() ); |
|
| 500 | + return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name()); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | |
@@ -510,8 +510,8 @@ discard block |
||
| 510 | 510 | * @return \EE_Payment_Method_Form |
| 511 | 511 | * @throws \EE_Error |
| 512 | 512 | */ |
| 513 | - protected function _simplify_form( $form_section, $payment_method_name = '' ){ |
|
| 514 | - if ( $form_section instanceof EE_Payment_Method_Form ) { |
|
| 513 | + protected function _simplify_form($form_section, $payment_method_name = '') { |
|
| 514 | + if ($form_section instanceof EE_Payment_Method_Form) { |
|
| 515 | 515 | $form_section->exclude( |
| 516 | 516 | array( |
| 517 | 517 | 'PMD_type', //dont want them changing the type |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | ); |
| 523 | 523 | return $form_section; |
| 524 | 524 | } else { |
| 525 | - throw new EE_Error( sprintf( __( 'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', 'event_espresso' ), $payment_method_name )); |
|
| 525 | + throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', 'event_espresso'), $payment_method_name)); |
|
| 526 | 526 | } |
| 527 | 527 | } |
| 528 | 528 | |
@@ -535,18 +535,18 @@ discard block |
||
| 535 | 535 | * @param \EE_Payment_Method $payment_method |
| 536 | 536 | * @return \EE_Form_Section_HTML |
| 537 | 537 | */ |
| 538 | - protected function _update_payment_method_button( EE_Payment_Method $payment_method ) { |
|
| 538 | + protected function _update_payment_method_button(EE_Payment_Method $payment_method) { |
|
| 539 | 539 | $update_button = new EE_Submit_Input( |
| 540 | 540 | array( |
| 541 | - 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
| 542 | - 'default' => sprintf( __( 'Update %s Payment Settings', 'event_espresso' ), $payment_method->admin_name() ), |
|
| 541 | + 'html_id' => 'save_'.$payment_method->slug().'_settings', |
|
| 542 | + 'default' => sprintf(__('Update %s Payment Settings', 'event_espresso'), $payment_method->admin_name()), |
|
| 543 | 543 | 'html_label' => EEH_HTML::nbsp() |
| 544 | 544 | ) |
| 545 | 545 | ); |
| 546 | 546 | return new EE_Form_Section_HTML( |
| 547 | - EEH_HTML::no_row( EEH_HTML::br(2) ) . |
|
| 547 | + EEH_HTML::no_row(EEH_HTML::br(2)). |
|
| 548 | 548 | EEH_HTML::tr( |
| 549 | - EEH_HTML::th( __( 'Update Settings', 'event_espresso') ) . |
|
| 549 | + EEH_HTML::th(__('Update Settings', 'event_espresso')). |
|
| 550 | 550 | EEH_HTML::td( |
| 551 | 551 | $update_button->get_html_for_input() |
| 552 | 552 | ) |
@@ -563,11 +563,11 @@ discard block |
||
| 563 | 563 | * @param \EE_Payment_Method $payment_method |
| 564 | 564 | * @return \EE_Form_Section_Proper |
| 565 | 565 | */ |
| 566 | - protected function _deactivate_payment_method_button( EE_Payment_Method $payment_method ) { |
|
| 567 | - $link_text_and_title = sprintf( __( 'Deactivate %1$s Payments?', 'event_espresso'), $payment_method->admin_name() ); |
|
| 566 | + protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) { |
|
| 567 | + $link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'), $payment_method->admin_name()); |
|
| 568 | 568 | return new EE_Form_Section_HTML( |
| 569 | 569 | EEH_HTML::tr( |
| 570 | - EEH_HTML::th( __( 'Deactivate Payment Method', 'event_espresso') ) . |
|
| 570 | + EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')). |
|
| 571 | 571 | EEH_HTML::td( |
| 572 | 572 | EEH_HTML::link( |
| 573 | 573 | EE_Admin_Page::add_query_args_and_nonce( |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | ), |
| 580 | 580 | $link_text_and_title, |
| 581 | 581 | $link_text_and_title, |
| 582 | - 'deactivate_' . $payment_method->slug(), |
|
| 582 | + 'deactivate_'.$payment_method->slug(), |
|
| 583 | 583 | 'espresso-button button-secondary' |
| 584 | 584 | ) |
| 585 | 585 | ) |
@@ -595,12 +595,12 @@ discard block |
||
| 595 | 595 | * @param \EE_Payment_Method $payment_method |
| 596 | 596 | * @return \EE_Form_Section_Proper |
| 597 | 597 | */ |
| 598 | - protected function _activate_payment_method_button( EE_Payment_Method $payment_method ) { |
|
| 599 | - $link_text_and_title = sprintf( __( 'Activate %1$s Payment Method?', 'event_espresso'), $payment_method->admin_name() ); |
|
| 598 | + protected function _activate_payment_method_button(EE_Payment_Method $payment_method) { |
|
| 599 | + $link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'), $payment_method->admin_name()); |
|
| 600 | 600 | return new EE_Form_Section_Proper( |
| 601 | 601 | array( |
| 602 | - 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
| 603 | - 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
| 602 | + 'name' => 'activate_'.$payment_method->slug().'_settings_form', |
|
| 603 | + 'html_id' => 'activate_'.$payment_method->slug().'_settings_form', |
|
| 604 | 604 | 'action' => '#', |
| 605 | 605 | 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
| 606 | 606 | 'subsections' => apply_filters( |
@@ -609,8 +609,8 @@ discard block |
||
| 609 | 609 | new EE_Form_Section_HTML( |
| 610 | 610 | EEH_HTML::tr( |
| 611 | 611 | EEH_HTML::th( |
| 612 | - EEH_HTML::label( __( 'Click to Activate ', 'event_espresso' )) |
|
| 613 | - ) . |
|
| 612 | + EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
|
| 613 | + ). |
|
| 614 | 614 | EEH_HTML::td( |
| 615 | 615 | EEH_HTML::link( |
| 616 | 616 | EE_Admin_Page::add_query_args_and_nonce( |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | ), |
| 623 | 623 | $link_text_and_title, |
| 624 | 624 | $link_text_and_title, |
| 625 | - 'activate_' . $payment_method->slug(), |
|
| 625 | + 'activate_'.$payment_method->slug(), |
|
| 626 | 626 | 'espresso-button-green button-primary' |
| 627 | 627 | ) |
| 628 | 628 | ) |
@@ -644,9 +644,9 @@ discard block |
||
| 644 | 644 | protected function _fine_print() { |
| 645 | 645 | return new EE_Form_Section_HTML( |
| 646 | 646 | EEH_HTML::tr( |
| 647 | - EEH_HTML::th() . |
|
| 647 | + EEH_HTML::th(). |
|
| 648 | 648 | EEH_HTML::td( |
| 649 | - EEH_HTML::p( __( 'All fields marked with a * are required fields', 'event_espresso' ), '', 'grey-text' ) |
|
| 649 | + EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
|
| 650 | 650 | ) |
| 651 | 651 | ) |
| 652 | 652 | ); |
@@ -658,15 +658,15 @@ discard block |
||
| 658 | 658 | * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far) |
| 659 | 659 | * @global WP_User $current_user |
| 660 | 660 | */ |
| 661 | - protected function _activate_payment_method(){ |
|
| 662 | - if(isset($this->_req_data['payment_method_type'])){ |
|
| 661 | + protected function _activate_payment_method() { |
|
| 662 | + if (isset($this->_req_data['payment_method_type'])) { |
|
| 663 | 663 | $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']); |
| 664 | 664 | //see if one exists |
| 665 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
| 666 | - $payment_method = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type( $payment_method_type ); |
|
| 665 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 666 | + $payment_method = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type($payment_method_type); |
|
| 667 | 667 | |
| 668 | - $this->_redirect_after_action(1, 'Payment Method', 'activated', array('action' => 'default','payment_method'=>$payment_method->slug())); |
|
| 669 | - }else{ |
|
| 668 | + $this->_redirect_after_action(1, 'Payment Method', 'activated', array('action' => 'default', 'payment_method'=>$payment_method->slug())); |
|
| 669 | + } else { |
|
| 670 | 670 | $this->_redirect_after_action(FALSE, 'Payment Method', 'activated', array('action' => 'default')); |
| 671 | 671 | } |
| 672 | 672 | } |
@@ -674,14 +674,14 @@ discard block |
||
| 674 | 674 | /** |
| 675 | 675 | * Deactivates the payment method with the specified slug, and redirects. |
| 676 | 676 | */ |
| 677 | - protected function _deactivate_payment_method(){ |
|
| 678 | - if(isset($this->_req_data['payment_method'])){ |
|
| 677 | + protected function _deactivate_payment_method() { |
|
| 678 | + if (isset($this->_req_data['payment_method'])) { |
|
| 679 | 679 | $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
| 680 | 680 | //deactivate it |
| 681 | 681 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
| 682 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method( $payment_method_slug ); |
|
| 683 | - $this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated', array('action' => 'default','payment_method'=>$payment_method_slug)); |
|
| 684 | - }else{ |
|
| 682 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug); |
|
| 683 | + $this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated', array('action' => 'default', 'payment_method'=>$payment_method_slug)); |
|
| 684 | + } else { |
|
| 685 | 685 | $this->_redirect_after_action(FALSE, 'Payment Method', 'deactivated', array('action' => 'default')); |
| 686 | 686 | } |
| 687 | 687 | } |
@@ -695,39 +695,39 @@ discard block |
||
| 695 | 695 | * subsequently called 'headers_sent_func' which is _payment_methods_list) |
| 696 | 696 | * @return void |
| 697 | 697 | */ |
| 698 | - protected function _update_payment_method(){ |
|
| 699 | - if( $_SERVER['REQUEST_METHOD'] == 'POST'){ |
|
| 698 | + protected function _update_payment_method() { |
|
| 699 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 700 | 700 | //ok let's find which gateway form to use based on the form input |
| 701 | 701 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
| 702 | 702 | /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */ |
| 703 | 703 | $correct_pmt_form_to_use = NULL; |
| 704 | 704 | $pmt_obj = NULL; |
| 705 | - foreach(EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj){ |
|
| 705 | + foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { |
|
| 706 | 706 | /** @var $pmt_obj EE_PMT_Base */ |
| 707 | 707 | //get the form and simplify it, like what we do when we display it |
| 708 | 708 | $pmt_form = $pmt_obj->settings_form(); |
| 709 | 709 | $this->_simplify_form($pmt_form); |
| 710 | - if($pmt_form->form_data_present_in($this->_req_data)){ |
|
| 710 | + if ($pmt_form->form_data_present_in($this->_req_data)) { |
|
| 711 | 711 | $correct_pmt_form_to_use = $pmt_form; |
| 712 | 712 | break; |
| 713 | 713 | } |
| 714 | 714 | } |
| 715 | 715 | //if we couldn't find the correct payment method type... |
| 716 | - if( ! $correct_pmt_form_to_use ){ |
|
| 716 | + if ( ! $correct_pmt_form_to_use) { |
|
| 717 | 717 | EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support", 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
| 718 | 718 | $this->_redirect_after_action(FALSE, 'Payment Method', 'activated', array('action' => 'default')); |
| 719 | 719 | } |
| 720 | 720 | $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
| 721 | - if($correct_pmt_form_to_use->is_valid()){ |
|
| 721 | + if ($correct_pmt_form_to_use->is_valid()) { |
|
| 722 | 722 | $correct_pmt_form_to_use->save(); |
| 723 | 723 | $pm = $correct_pmt_form_to_use->get_model_object(); |
| 724 | 724 | /** @var $pm EE_Payment_Method */ |
| 725 | - $this->_redirect_after_action(TRUE, 'Payment Method', 'updated', array('action' => 'default','payment_method'=>$pm->slug())); |
|
| 726 | - }else{ |
|
| 725 | + $this->_redirect_after_action(TRUE, 'Payment Method', 'updated', array('action' => 'default', 'payment_method'=>$pm->slug())); |
|
| 726 | + } else { |
|
| 727 | 727 | EE_Error::add_error( |
| 728 | 728 | sprintf( |
| 729 | 729 | __('Payment method of type %s was not saved because there were validation errors. They have been marked in the form', 'event_espresso'), |
| 730 | - $pmt_obj instanceof EE_PMT_Base ? $pmt_obj->pretty_name() : __( '"(unknown)"', 'event_espresso' ) |
|
| 730 | + $pmt_obj instanceof EE_PMT_Base ? $pmt_obj->pretty_name() : __('"(unknown)"', 'event_espresso') |
|
| 731 | 731 | ), |
| 732 | 732 | __FILE__, |
| 733 | 733 | __FUNCTION__, |
@@ -744,11 +744,11 @@ discard block |
||
| 744 | 744 | protected function _payment_settings() { |
| 745 | 745 | |
| 746 | 746 | $this->_template_args['values'] = $this->_yes_no_values; |
| 747 | - $this->_template_args['show_pending_payment_options'] = isset( EE_Registry::instance()->CFG->registration->show_pending_payment_options ) ? absint( EE_Registry::instance()->CFG->registration->show_pending_payment_options ) : FALSE; |
|
| 747 | + $this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options) ? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : FALSE; |
|
| 748 | 748 | |
| 749 | - $this->_set_add_edit_form_tags( 'update_payment_settings' ); |
|
| 750 | - $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 751 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( EE_PAYMENTS_TEMPLATE_PATH . 'payment_settings.template.php', $this->_template_args, TRUE ); |
|
| 749 | + $this->_set_add_edit_form_tags('update_payment_settings'); |
|
| 750 | + $this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE); |
|
| 751 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH.'payment_settings.template.php', $this->_template_args, TRUE); |
|
| 752 | 752 | $this->display_admin_page_with_sidebar(); |
| 753 | 753 | |
| 754 | 754 | } |
@@ -762,13 +762,13 @@ discard block |
||
| 762 | 762 | * @return array |
| 763 | 763 | */ |
| 764 | 764 | protected function _update_payment_settings() { |
| 765 | - EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset( $this->_req_data['show_pending_payment_options'] ) ? $this->_req_data['show_pending_payment_options'] : FALSE; |
|
| 766 | - EE_Registry::instance()->CFG = apply_filters( 'FHEE__Payments_Admin_Page___update_payment_settings__CFG', EE_Registry::instance()->CFG ); |
|
| 765 | + EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options']) ? $this->_req_data['show_pending_payment_options'] : FALSE; |
|
| 766 | + EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG', EE_Registry::instance()->CFG); |
|
| 767 | 767 | |
| 768 | 768 | |
| 769 | - $what = __('Payment Settings','event_espresso'); |
|
| 770 | - $success = $this->_update_espresso_configuration( $what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 771 | - $this->_redirect_after_action( $success, $what, __('updated','event_espresso'), array( 'action' => 'payment_settings' ) ); |
|
| 769 | + $what = __('Payment Settings', 'event_espresso'); |
|
| 770 | + $success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, __LINE__); |
|
| 771 | + $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), array('action' => 'payment_settings')); |
|
| 772 | 772 | |
| 773 | 773 | } |
| 774 | 774 | protected function _payment_log_overview_list_table() { |
@@ -794,18 +794,18 @@ discard block |
||
| 794 | 794 | * @param bool $count |
| 795 | 795 | * @return array |
| 796 | 796 | */ |
| 797 | - public function get_payment_logs($per_page = 50, $current_page = 0, $count = false){ |
|
| 798 | - EE_Registry::instance()->load_model( 'Change_Log' ); |
|
| 797 | + public function get_payment_logs($per_page = 50, $current_page = 0, $count = false) { |
|
| 798 | + EE_Registry::instance()->load_model('Change_Log'); |
|
| 799 | 799 | //we may need to do multiple queries (joining differently), so we actually wan tan array of query params |
| 800 | - $query_params = array(array('LOG_type'=> EEM_Change_Log::type_gateway)); |
|
| 800 | + $query_params = array(array('LOG_type'=> EEM_Change_Log::type_gateway)); |
|
| 801 | 801 | //check if they've selected a specific payment method |
| 802 | - if( isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all'){ |
|
| 802 | + if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') { |
|
| 803 | 803 | $query_params[0]['OR*pm_or_pay_pm'] = array('Payment.Payment_Method.PMD_ID'=>$this->_req_data['_payment_method'], |
| 804 | 804 | 'Payment_Method.PMD_ID'=>$this->_req_data['_payment_method']); |
| 805 | 805 | } |
| 806 | 806 | //take into account search |
| 807 | - if(isset($this->_req_data['s']) && $this->_req_data['s']){ |
|
| 808 | - $similarity_string = array('LIKE','%'.str_replace("","%",$this->_req_data['s']) .'%'); |
|
| 807 | + if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
|
| 808 | + $similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%'); |
|
| 809 | 809 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
| 810 | 810 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
| 811 | 811 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
@@ -820,48 +820,48 @@ discard block |
||
| 820 | 820 | $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
| 821 | 821 | |
| 822 | 822 | } |
| 823 | - if(isset( $this->_req_data['payment-filter-start-date'] ) && isset( $this->_req_data['payment-filter-end-date'] )){ |
|
| 823 | + if (isset($this->_req_data['payment-filter-start-date']) && isset($this->_req_data['payment-filter-end-date'])) { |
|
| 824 | 824 | //add date |
| 825 | - $start_date =wp_strip_all_tags( $this->_req_data['payment-filter-start-date'] ); |
|
| 826 | - $end_date = wp_strip_all_tags( $this->_req_data['payment-filter-end-date'] ); |
|
| 825 | + $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
|
| 826 | + $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
|
| 827 | 827 | //make sure our timestamps start and end right at the boundaries for each day |
| 828 | - $start_date = date( 'Y-m-d', strtotime( $start_date ) ) . ' 00:00:00'; |
|
| 829 | - $end_date = date( 'Y-m-d', strtotime( $end_date ) ) . ' 23:59:59'; |
|
| 828 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
| 829 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
| 830 | 830 | |
| 831 | 831 | //convert to timestamps |
| 832 | - $start_date = strtotime( $start_date ); |
|
| 833 | - $end_date = strtotime( $end_date ); |
|
| 832 | + $start_date = strtotime($start_date); |
|
| 833 | + $end_date = strtotime($end_date); |
|
| 834 | 834 | |
| 835 | 835 | //makes sure start date is the lowest value and vice versa |
| 836 | - $start_date = min( $start_date, $end_date ); |
|
| 837 | - $end_date = max( $start_date, $end_date ); |
|
| 836 | + $start_date = min($start_date, $end_date); |
|
| 837 | + $end_date = max($start_date, $end_date); |
|
| 838 | 838 | |
| 839 | 839 | //convert for query |
| 840 | - $start_date = EEM_Change_Log::instance()->convert_datetime_for_query( 'LOG_time', date( 'Y-m-d H:i:s', $start_date ), 'Y-m-d H:i:s' ); |
|
| 841 | - $end_date = EEM_Change_Log::instance()->convert_datetime_for_query( 'LOG_time', date( 'Y-m-d H:i:s', $end_date ), 'Y-m-d H:i:s' ); |
|
| 840 | + $start_date = EEM_Change_Log::instance()->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); |
|
| 841 | + $end_date = EEM_Change_Log::instance()->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); |
|
| 842 | 842 | |
| 843 | - $query_params[0]['LOG_time'] = array('BETWEEN',array($start_date,$end_date)); |
|
| 843 | + $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date)); |
|
| 844 | 844 | |
| 845 | 845 | } |
| 846 | - if($count){ |
|
| 846 | + if ($count) { |
|
| 847 | 847 | return EEM_Change_Log::instance()->count($query_params); |
| 848 | 848 | } |
| 849 | - if(isset($this->_req_data['order'])){ |
|
| 850 | - $sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'DESC'; |
|
| 849 | + if (isset($this->_req_data['order'])) { |
|
| 850 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; |
|
| 851 | 851 | $query_params['order_by'] = array('LOG_time' => $sort); |
| 852 | - }else{ |
|
| 852 | + } else { |
|
| 853 | 853 | $query_params['order_by'] = array('LOG_time' => 'DESC'); |
| 854 | 854 | } |
| 855 | - $offset = ($current_page-1)*$per_page; |
|
| 855 | + $offset = ($current_page - 1) * $per_page; |
|
| 856 | 856 | |
| 857 | - if( ! isset($this->_req_data['download_results'])){ |
|
| 858 | - $query_params['limit'] = array( $offset, $per_page ); |
|
| 857 | + if ( ! isset($this->_req_data['download_results'])) { |
|
| 858 | + $query_params['limit'] = array($offset, $per_page); |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | |
| 862 | 862 | |
| 863 | 863 | //now they've requested to instead just download the file instead of viewing it. |
| 864 | - if(isset($this->_req_data['download_results'])){ |
|
| 864 | + if (isset($this->_req_data['download_results'])) { |
|
| 865 | 865 | $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
| 866 | 866 | header('Content-Disposition: attachment'); |
| 867 | 867 | header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url())); |
@@ -883,36 +883,36 @@ discard block |
||
| 883 | 883 | * @param EE_Change_Log $logB |
| 884 | 884 | * @return int |
| 885 | 885 | */ |
| 886 | - protected function _sort_logs_again($logA,$logB){ |
|
| 886 | + protected function _sort_logs_again($logA, $logB) { |
|
| 887 | 887 | $timeA = $logA->get_raw('LOG_time'); |
| 888 | 888 | $timeB = $logB->get_raw('LOG_time'); |
| 889 | - if($timeA == $timeB){ |
|
| 889 | + if ($timeA == $timeB) { |
|
| 890 | 890 | return 0; |
| 891 | 891 | } |
| 892 | 892 | $comparison = $timeA < $timeB ? -1 : 1; |
| 893 | - if(strtoupper($this->_sort_logs_again_direction) == 'DESC'){ |
|
| 893 | + if (strtoupper($this->_sort_logs_again_direction) == 'DESC') { |
|
| 894 | 894 | return $comparison * -1; |
| 895 | - }else{ |
|
| 895 | + } else { |
|
| 896 | 896 | return $comparison; |
| 897 | 897 | } |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | protected function _payment_log_details() { |
| 901 | - EE_Registry::instance()->load_model( 'Change_Log' ); |
|
| 901 | + EE_Registry::instance()->load_model('Change_Log'); |
|
| 902 | 902 | /** @var $payment_log EE_Change_Log */ |
| 903 | 903 | $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']); |
| 904 | 904 | $payment_method = NULL; |
| 905 | 905 | $transaction = NULL; |
| 906 | - if( $payment_log instanceof EE_Change_Log ){ |
|
| 907 | - if( $payment_log->object() instanceof EE_Payment ){ |
|
| 906 | + if ($payment_log instanceof EE_Change_Log) { |
|
| 907 | + if ($payment_log->object() instanceof EE_Payment) { |
|
| 908 | 908 | $payment_method = $payment_log->object()->payment_method(); |
| 909 | 909 | $transaction = $payment_log->object()->transaction(); |
| 910 | - }elseif($payment_log->object() instanceof EE_Payment_Method){ |
|
| 910 | + }elseif ($payment_log->object() instanceof EE_Payment_Method) { |
|
| 911 | 911 | $payment_method = $payment_log->object(); |
| 912 | 912 | } |
| 913 | 913 | } |
| 914 | 914 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 915 | - EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
| 915 | + EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php', |
|
| 916 | 916 | array( |
| 917 | 917 | 'payment_log'=>$payment_log, |
| 918 | 918 | 'payment_method'=>$payment_method, |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | protected $_job_step_response = null; |
| 38 | 38 | |
| 39 | 39 | |
| 40 | - public function __construct( $routing = TRUE ) { |
|
| 41 | - parent::__construct( $routing ); |
|
| 40 | + public function __construct($routing = TRUE) { |
|
| 41 | + parent::__construct($routing); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | |
| 55 | 55 | protected function _ajax_hooks() { |
| 56 | - add_action('wp_ajax_espresso_batch_continue',array($this,'batch_continue')); |
|
| 57 | - add_action('wp_ajax_espresso_batch_cleanup',array($this,'batch_cleanup')); |
|
| 56 | + add_action('wp_ajax_espresso_batch_continue', array($this, 'batch_continue')); |
|
| 57 | + add_action('wp_ajax_espresso_batch_cleanup', array($this, 'batch_cleanup')); |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | 'nav' => array( |
| 103 | 103 | 'label' => __('Shortcodes', 'event_espresso'), |
| 104 | 104 | 'order' => 30), |
| 105 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_shortcodes_boxes' ) ), |
|
| 105 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_shortcodes_boxes')), |
|
| 106 | 106 | 'require_nonce' => FALSE |
| 107 | 107 | ), |
| 108 | 108 | 'contact_support' => array( |
| 109 | 109 | 'nav' => array( |
| 110 | 110 | 'label' => __('Support', 'event_espresso'), |
| 111 | 111 | 'order' => 40), |
| 112 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_support_boxes' ) ), |
|
| 112 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_support_boxes')), |
|
| 113 | 113 | 'require_nonce' => FALSE |
| 114 | 114 | ), |
| 115 | 115 | 'developers' => array( |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | |
| 139 | 139 | protected function _installation() { |
| 140 | - $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php'; |
|
| 141 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( $template_path, '', TRUE); |
|
| 140 | + $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH.'support_admin_details_installation.template.php'; |
|
| 141 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, '', TRUE); |
|
| 142 | 142 | $this->display_admin_page_with_sidebar(); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | 'other_resources' => __('Other Resources', 'event_espresso') |
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | - foreach ( $boxes as $box => $label ) { |
|
| 167 | - $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_' . $box . '.template.php'; |
|
| 166 | + foreach ($boxes as $box => $label) { |
|
| 167 | + $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH.'support_admin_details_'.$box.'.template.php'; |
|
| 168 | 168 | $callback_args = array('template_path' => $template_path); |
| 169 | - add_meta_box( 'espresso_' . $box . '_settings', $label, create_function('$post, $metabox', 'echo EEH_Template::display_template( $metabox["args"]["template_path"], "", TRUE );'), $this->_current_screen_id, 'normal', 'high', $callback_args); |
|
| 169 | + add_meta_box('espresso_'.$box.'_settings', $label, create_function('$post, $metabox', 'echo EEH_Template::display_template( $metabox["args"]["template_path"], "", TRUE );'), $this->_current_screen_id, 'normal', 'high', $callback_args); |
|
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
@@ -187,15 +187,15 @@ discard block |
||
| 187 | 187 | 'shortcodes_event_listings' => __('Event Listings', 'event_espresso'), |
| 188 | 188 | 'shortcodes_ticket_selector' => __('Event Ticket Selector', 'event_espresso'), |
| 189 | 189 | 'shortcodes_category' => __('Event Categories', 'event_espresso'), |
| 190 | - 'shortcodes_attendee' => __( 'Event Attendees', 'event_espresso' ) |
|
| 190 | + 'shortcodes_attendee' => __('Event Attendees', 'event_espresso') |
|
| 191 | 191 | /*'shortcodes_single_events' => __('Single Events', 'event_espresso'),*/ |
| 192 | 192 | /*'shortcodes_attendee_listings' => __('Attendee Listings', 'event_espresso'),*/ |
| 193 | 193 | ); |
| 194 | 194 | |
| 195 | - foreach ( $boxes as $box => $label ) { |
|
| 196 | - $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_' . $box . '.template.php'; |
|
| 195 | + foreach ($boxes as $box => $label) { |
|
| 196 | + $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH.'support_admin_details_'.$box.'.template.php'; |
|
| 197 | 197 | $callback_args = array('template_path' => $template_path); |
| 198 | - add_meta_box( 'espresso_' . $box . '_settings', $label, create_function('$post, $metabox', 'echo EEH_Template::display_template( $metabox["args"]["template_path"], "", TRUE );'), $this->_current_screen_id, 'normal', 'high', $callback_args); |
|
| 198 | + add_meta_box('espresso_'.$box.'_settings', $label, create_function('$post, $metabox', 'echo EEH_Template::display_template( $metabox["args"]["template_path"], "", TRUE );'), $this->_current_screen_id, 'normal', 'high', $callback_args); |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | |
@@ -214,41 +214,41 @@ discard block |
||
| 214 | 214 | 'important_information' => __('Important Information', 'event_espresso') |
| 215 | 215 | ); |
| 216 | 216 | |
| 217 | - foreach ( $boxes as $box => $label ) { |
|
| 218 | - $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_' . $box . '.template.php'; |
|
| 217 | + foreach ($boxes as $box => $label) { |
|
| 218 | + $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH.'support_admin_details_'.$box.'.template.php'; |
|
| 219 | 219 | $callback_args = array('template_path' => $template_path, 'template_args' => $this->_template_args); |
| 220 | - add_meta_box( 'espresso_' . $box . '_settings', $label, create_function('$post, $metabox', 'echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );'), $this->_current_screen_id, 'normal', 'high', $callback_args); |
|
| 220 | + add_meta_box('espresso_'.$box.'_settings', $label, create_function('$post, $metabox', 'echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );'), $this->_current_screen_id, 'normal', 'high', $callback_args); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | |
| 225 | 225 | protected function _developers() { |
| 226 | - $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php'; |
|
| 227 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, array(), true ); |
|
| 226 | + $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH.'developers_admin_details.template.php'; |
|
| 227 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, array(), true); |
|
| 228 | 228 | $this->display_admin_page_with_sidebar(); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | public function load_scripts_styles_batch_create() { |
| 232 | 232 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
| 233 | - wp_enqueue_script( 'batch_runner', EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', array( 'progress_bar' )); |
|
| 234 | - wp_localize_script( 'support_batch_runner', 'ee_job_response', $job_response->to_array() ); |
|
| 235 | - wp_localize_script( 'support_batch_runner', 'ee_job_i18n', |
|
| 233 | + wp_enqueue_script('batch_runner', EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', array('progress_bar')); |
|
| 234 | + wp_localize_script('support_batch_runner', 'ee_job_response', $job_response->to_array()); |
|
| 235 | + wp_localize_script('support_batch_runner', 'ee_job_i18n', |
|
| 236 | 236 | array( |
| 237 | - 'redirect_url' => $this->_req_data['redirect_url' ], |
|
| 237 | + 'redirect_url' => $this->_req_data['redirect_url'], |
|
| 238 | 238 | )); |
| 239 | 239 | } |
| 240 | 240 | public function load_scripts_styles_batch_file_create() { |
| 241 | 241 | //creates a job based on the request variable |
| 242 | 242 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
| 243 | - wp_enqueue_script( 'support_batch_file_runner', EE_SUPPORT_ASSETS_URL . 'support_batch_file_runner.js', array( 'batch_runner' ), EVENT_ESPRESSO_VERSION,true); |
|
| 244 | - wp_localize_script( 'support_batch_file_runner', 'ee_job_response', $job_response->to_array() ); |
|
| 245 | - wp_localize_script( 'support_batch_file_runner', 'ee_job_i18n', |
|
| 243 | + wp_enqueue_script('support_batch_file_runner', EE_SUPPORT_ASSETS_URL.'support_batch_file_runner.js', array('batch_runner'), EVENT_ESPRESSO_VERSION, true); |
|
| 244 | + wp_localize_script('support_batch_file_runner', 'ee_job_response', $job_response->to_array()); |
|
| 245 | + wp_localize_script('support_batch_file_runner', 'ee_job_i18n', |
|
| 246 | 246 | array( |
| 247 | 247 | 'download_and_redirecting' => sprintf( |
| 248 | 248 | __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
| 249 | - '<a href="' . $this->_req_data['redirect_url' ] .'">', |
|
| 249 | + '<a href="'.$this->_req_data['redirect_url'].'">', |
|
| 250 | 250 | '</a>' ), |
| 251 | - 'redirect_url' => $this->_req_data['redirect_url' ], |
|
| 251 | + 'redirect_url' => $this->_req_data['redirect_url'], |
|
| 252 | 252 | )); |
| 253 | 253 | } |
| 254 | 254 | |
@@ -259,16 +259,16 @@ discard block |
||
| 259 | 259 | * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
| 260 | 260 | */ |
| 261 | 261 | protected function _enqueue_batch_job_scripts_and_styles_and_start_job() { |
| 262 | - wp_register_script( 'progress_bar', EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', array( 'jquery' ) ); |
|
| 263 | - wp_enqueue_style( 'progress_bar', EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 264 | - wp_enqueue_script( 'batch_runner', EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', array( 'progress_bar' )); |
|
| 265 | - $job_handler_classname = stripslashes( $this->_req_data[ 'job_handler' ] ); |
|
| 262 | + wp_register_script('progress_bar', EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js', array('jquery')); |
|
| 263 | + wp_enqueue_style('progress_bar', EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 264 | + wp_enqueue_script('batch_runner', EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', array('progress_bar')); |
|
| 265 | + $job_handler_classname = stripslashes($this->_req_data['job_handler']); |
|
| 266 | 266 | $request_data = array_diff_key( |
| 267 | 267 | $this->_req_data, |
| 268 | - array_flip( array( 'action', 'page' ) ) ); |
|
| 268 | + array_flip(array('action', 'page')) ); |
|
| 269 | 269 | $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor(); |
| 270 | 270 | //eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
| 271 | - $job_response = $batch_runner->create_job( $job_handler_classname, $request_data ); |
|
| 271 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
| 272 | 272 | //remember the response for later. We need it to display the page body |
| 273 | 273 | $this->_job_step_response = $job_response; |
| 274 | 274 | return $job_response; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | * Invokes the report-generating code |
| 278 | 278 | */ |
| 279 | 279 | protected function batch_create() { |
| 280 | - echo EEH_Template::locate_template( EE_SUPPORT_ADMIN . 'templates' . DS . 'admin_batch_runner.template.html' ); |
|
| 280 | + echo EEH_Template::locate_template(EE_SUPPORT_ADMIN.'templates'.DS.'admin_batch_runner.template.html'); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -285,13 +285,13 @@ discard block |
||
| 285 | 285 | * and then sends the user back to wherever they were before |
| 286 | 286 | */ |
| 287 | 287 | protected function batch_file_create() { |
| 288 | - if( $this->_job_step_response instanceof \EventEspressoBatchRequest\Helpers\JobStepResponse ) { |
|
| 289 | - $filename = EEH_File::get_filename_from_filepath( $this->_job_step_response->job_parameters()->extra_datum( 'filepath' ) ); |
|
| 288 | + if ($this->_job_step_response instanceof \EventEspressoBatchRequest\Helpers\JobStepResponse) { |
|
| 289 | + $filename = EEH_File::get_filename_from_filepath($this->_job_step_response->job_parameters()->extra_datum('filepath')); |
|
| 290 | 290 | } else { |
| 291 | - $filename = __( 'Unknown', 'event_espresso' ); |
|
| 291 | + $filename = __('Unknown', 'event_espresso'); |
|
| 292 | 292 | } |
| 293 | 293 | echo EEH_Template::locate_template( |
| 294 | - EE_SUPPORT_ADMIN . 'templates' . DS . 'admin_batch_file_runner.template.html', |
|
| 294 | + EE_SUPPORT_ADMIN.'templates'.DS.'admin_batch_file_runner.template.html', |
|
| 295 | 295 | array( |
| 296 | 296 | 'filename' => $filename |
| 297 | 297 | ) |
@@ -302,10 +302,10 @@ discard block |
||
| 302 | 302 | * Receives ajax calls for continuing a job |
| 303 | 303 | */ |
| 304 | 304 | public function batch_continue() { |
| 305 | - $job_id = sanitize_text_field( $this->_req_data[ 'job_id' ] ); |
|
| 305 | + $job_id = sanitize_text_field($this->_req_data['job_id']); |
|
| 306 | 306 | $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor(); |
| 307 | - $responseobj = $batch_runner->continue_job( $job_id); |
|
| 308 | - $this->_template_args[ 'data' ] = $responseobj->to_array(); |
|
| 307 | + $responseobj = $batch_runner->continue_job($job_id); |
|
| 308 | + $this->_template_args['data'] = $responseobj->to_array(); |
|
| 309 | 309 | $this->_return_json(); |
| 310 | 310 | } |
| 311 | 311 | |
@@ -314,10 +314,10 @@ discard block |
||
| 314 | 314 | * @return type |
| 315 | 315 | */ |
| 316 | 316 | public function batch_cleanup() { |
| 317 | - $job_id = sanitize_text_field( $this->_req_data[ 'job_id' ] ); |
|
| 317 | + $job_id = sanitize_text_field($this->_req_data['job_id']); |
|
| 318 | 318 | $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor(); |
| 319 | - $response_obj = $batch_runner->cleanup_job( $job_id ); |
|
| 320 | - $this->_template_args[ 'data' ] = $response_obj->to_array(); |
|
| 319 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
| 320 | + $this->_template_args['data'] = $response_obj->to_array(); |
|
| 321 | 321 | $this->_return_json(); |
| 322 | 322 | } |
| 323 | 323 | |