diff --git a/admin/class-openedx-commerce-admin.php b/admin/class-openedx-commerce-admin.php index 292e7cd..81b7b4f 100644 --- a/admin/class-openedx-commerce-admin.php +++ b/admin/class-openedx-commerce-admin.php @@ -9,12 +9,12 @@ * @since 1.0.0 */ -namespace App\admin; +namespace OpenedXCommerce\admin; -use App\model\Openedx_Commerce_Enrollment; -use App\model\Openedx_Commerce_Post_Type; -use App\admin\views\Openedx_Commerce_Enrollment_Info_Form; -use App\utils; +use OpenedXCommerce\model\Openedx_Commerce_Enrollment; +use OpenedXCommerce\model\Openedx_Commerce_Post_Type; +use OpenedXCommerce\admin\views\Openedx_Commerce_Enrollment_Info_Form; +use OpenedXCommerce\utils; /** * The admin-specific functionality of the plugin. @@ -316,7 +316,7 @@ public function add_admin_order_item_values( $product, $item, $item_id = null ) $order_url = esc_url( admin_url( 'post.php?post=' . intval( $input_value ) . '&action=edit' ) ); $html_output = ''; - $html_output .= ''; + $html_output .= ''; $html_output .= 'View Request'; $html_output .= ''; @@ -365,8 +365,8 @@ public function save_order_meta_data( $order_id ) { $items = wc_get_order( $order_id )->get_items(); foreach ( $items as $item_id => $item ) { - if ( isset( $_POST[ 'order_id_input' . $item_id ] ) ) { - $input_value = sanitize_text_field( wp_unslash( $_POST[ 'order_id_input' . $item_id ] ) ); + if ( isset( $_POST[ 'openedx_order_id_input' . $item_id ] ) ) { + $input_value = sanitize_text_field( wp_unslash( $_POST[ 'openedx_order_id_input' . $item_id ] ) ); update_post_meta( $order_id, 'enrollment_id' . $item_id, $input_value ); } } @@ -470,11 +470,11 @@ public function items_enrollment_request( $courses, $order_id, $billing_email, $ $action = 'enrollment_process'; $enrollment_arr = array( - 'enrollment_course_id' => $course_id, - 'enrollment_email' => $billing_email, - 'enrollment_mode' => $course_mode, - 'enrollment_request_type' => $request_type, - 'enrollment_order_id' => $order_id, + 'openedx_enrollment_course_id' => $course_id, + 'openedx_enrollment_email' => $billing_email, + 'openedx_enrollment_mode' => $course_mode, + 'openedx_enrollment_request_type' => $request_type, + 'openedx_enrollment_order_id' => $order_id, ); $enrollment_id = $this->openedx_enrollment->insert_new( $enrollment_arr, $action, $order_id ); diff --git a/admin/css/class-openedx-commerce-admin.css b/admin/css/class-openedx-commerce-admin.css index 4135ae0..0831f23 100644 --- a/admin/css/class-openedx-commerce-admin.css +++ b/admin/css/class-openedx-commerce-admin.css @@ -3,7 +3,7 @@ * included in this file. */ - .logs_box { + .openedx_logs_box { max-width: 100%; max-height: 477px; border: 1px solid #ccc; @@ -15,28 +15,28 @@ flex-direction: column-reverse; } -.log_entry { +.openedx_log_entry { background-color: #f2f2f2; border: 1px solid #ccc; padding: 10px; margin-bottom: 10px; } -.log_entry_api { +.openedx_log_entry_api { background-color: #f2f2f2; border: 1px solid #51ff00; padding: 10px; margin-bottom: 10px; } -.log_entry_api_error { +.openedx_log_entry_api_error { background-color: #f2f2f2; border: 1px solid #ff0000; padding: 10px; margin-bottom: 10px; } -.logs_box strong { +.openedx_logs_box strong { font-weight: bold; } @@ -48,7 +48,7 @@ flex: 1; } -#generate-jwt-token { +#openedx-generate-jwt-token { margin-left: 10px; } @@ -87,7 +87,7 @@ float: right; } -.tooltip-icon { +.openedx-tooltip-icon { font-size: 13px; color: white; position: relative; @@ -100,7 +100,7 @@ padding: 1px 6.5px 1px 6.5px; } -.tooltip-text { +.openedx-tooltip-text { display: none; font-size: 13px; padding: 2px 8px 3px 8px; @@ -113,7 +113,7 @@ margin-left: 5px; } -.tooltip-icon:hover + .tooltip-text { +.openedx-tooltip-icon:hover + .openedx-tooltip-text { display: inline-block; } diff --git a/admin/views/class-openedx-commerce-enrollment-info-form.php b/admin/views/class-openedx-commerce-enrollment-info-form.php index ff17185..5f97660 100644 --- a/admin/views/class-openedx-commerce-enrollment-info-form.php +++ b/admin/views/class-openedx-commerce-enrollment-info-form.php @@ -8,10 +8,10 @@ * @since 1.0.0 */ -namespace App\admin\views; +namespace OpenedXCommerce\admin\views; -use App\model\Openedx_Commerce_Log; -use App\utils; +use OpenedXCommerce\model\Openedx_Commerce_Log; +use OpenedXCommerce\utils; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -87,9 +87,9 @@ public function render_enrollment_info_form( $post ) { } $mode_options = utils\get_enrollment_options(); - $new_enrollment = false; + $openedx_new_enrollment = false; if ( ! $course_id && ! $email ) { - $new_enrollment = true; + $openedx_new_enrollment = true; } ?> @@ -97,13 +97,13 @@ public function render_enrollment_info_form( $post ) {

Open edX enrollment request

- + @@ -148,10 +148,10 @@ public function render_enrollment_info_form( $post ) { @@ -245,7 +245,7 @@ public function render_logs_box( $post ) { -
+
" readonly/>
- + diff --git a/composer.json b/composer.json index 195c168..2714eca 100644 --- a/composer.json +++ b/composer.json @@ -29,13 +29,13 @@ "test/" ], "psr-4": { - "App\\": "includes/", - "App\\model\\": "includes/model/", - "App\\admin\\": "admin/", - "App\\admin\\views\\": "admin/views/", - "App\\public\\": "public/", - "App\\utils\\": "utils/", - "App\\tests\\": "test/" + "OpenedXCommerce\\": "includes/", + "OpenedXCommerce\\model\\": "includes/model/", + "OpenedXCommerce\\admin\\": "admin/", + "OpenedXCommerce\\admin\\views\\": "admin/views/", + "OpenedXCommerce\\public\\": "public/", + "OpenedXCommerce\\utils\\": "utils/", + "OpenedXCommerce\\tests\\": "test/" } }, "require": { diff --git a/includes/class-openedx-commerce-activator.php b/includes/class-openedx-commerce-activator.php index b395732..384a1e3 100644 --- a/includes/class-openedx-commerce-activator.php +++ b/includes/class-openedx-commerce-activator.php @@ -9,7 +9,7 @@ * @subpackage Openedx_Commerce/includes */ -namespace App; +namespace OpenedXCommerce; /** * Fired during plugin activation. diff --git a/includes/class-openedx-commerce-deactivator.php b/includes/class-openedx-commerce-deactivator.php index ea53b7e..c9ceb19 100644 --- a/includes/class-openedx-commerce-deactivator.php +++ b/includes/class-openedx-commerce-deactivator.php @@ -9,7 +9,7 @@ * @subpackage Openedx_Commerce/includes */ -namespace App; +namespace OpenedXCommerce; /** * Fired during plugin deactivation. diff --git a/includes/class-openedx-commerce-i18n.php b/includes/class-openedx-commerce-i18n.php index 545aaee..19d9f73 100644 --- a/includes/class-openedx-commerce-i18n.php +++ b/includes/class-openedx-commerce-i18n.php @@ -12,7 +12,7 @@ * @subpackage Openedx_Commerce/includes */ -namespace App; +namespace OpenedXCommerce; /** * Define the internationalization functionality. diff --git a/includes/class-openedx-commerce-loader.php b/includes/class-openedx-commerce-loader.php index 9b8bdc8..59f0c6b 100644 --- a/includes/class-openedx-commerce-loader.php +++ b/includes/class-openedx-commerce-loader.php @@ -9,7 +9,7 @@ * @subpackage Openedx_Commerce/includes */ -namespace App; +namespace OpenedXCommerce; /** * Register all actions and filters for the plugin. diff --git a/includes/class-openedx-commerce.php b/includes/class-openedx-commerce.php index ac8700a..a942fec 100644 --- a/includes/class-openedx-commerce.php +++ b/includes/class-openedx-commerce.php @@ -14,12 +14,12 @@ * @author eduNEXT */ -namespace App; +namespace OpenedXCommerce; -use App\admin\Openedx_Commerce_Admin; -use App\public\Openedx_Commerce_Public; -use App\admin\views\Openedx_Commerce_Settings; -use App\model\Openedx_Commerce_Enrollment; +use OpenedXCommerce\admin\Openedx_Commerce_Admin; +use OpenedXCommerce\public\Openedx_Commerce_Public; +use OpenedXCommerce\admin\views\Openedx_Commerce_Settings; +use OpenedXCommerce\model\Openedx_Commerce_Enrollment; /** * This class contains the function to register a new custom post type. diff --git a/includes/model/class-openedx-commerce-api-calls.php b/includes/model/class-openedx-commerce-api-calls.php index ba17592..58b53ea 100644 --- a/includes/model/class-openedx-commerce-api-calls.php +++ b/includes/model/class-openedx-commerce-api-calls.php @@ -9,7 +9,7 @@ * @since 1.6.0 */ -namespace App\model; +namespace OpenedXCommerce\model; require_once plugin_dir_path( dirname( __DIR__ ) ) . 'vendor/autoload.php'; use DateTime; @@ -128,7 +128,7 @@ public function handle_request_error( $e ) { */ public function request_handler( $enrollment_data, $enrollment_action ) { - $request_type = $enrollment_data['enrollment_request_type']; + $request_type = $enrollment_data['openedx_enrollment_request_type']; $access_token = $this->check_access_token(); $access_token_string = $this->get_access_token( $access_token ); @@ -143,27 +143,27 @@ public function request_handler( $enrollment_data, $enrollment_action ) { $request_with_email_body = $this->get_enrollment_process_body( $enrollment_data, true, $access_token_string, $enrollment_action ); return $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $request_with_email_body, self::API_ENROLLMENT, 'POST' ); - } elseif ( 'enrollment_allowed' === $enrollment_action ) { + } elseif ( 'openedx_enrollment_allowed' === $enrollment_action ) { - $enrollment_allowed_request_body = $this->get_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ); + $openedx_enrollment_allowed_request_body = $this->get_openedx_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ); - if ( 'user_exists' === $enrollment_allowed_request_body[0] ) { + if ( 'user_exists' === $openedx_enrollment_allowed_request_body[0] ) { return $this->request_handler( $enrollment_data, 'enrollment_process' ); } else { - return $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $enrollment_allowed_request_body, self::API_ENROLLMENT_ALLOWED, 'POST' ); + return $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $openedx_enrollment_allowed_request_body, self::API_ENROLLMENT_ALLOWED, 'POST' ); } - } elseif ( 'enrollment_force' === $enrollment_action ) { + } elseif ( 'openedx_enrollment_force' === $enrollment_action ) { $request_with_email_body = $this->get_enrollment_process_body( $enrollment_data, true, $access_token_string, $enrollment_action ); return $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $request_with_email_body, self::API_ENROLLMENT, 'POST' ); - } elseif ( 'enrollment_allowed_force' === $enrollment_action ) { + } elseif ( 'openedx_enrollment_allowed_force' === $enrollment_action ) { - $enrollment_allowed_request_body = $this->get_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ); + $openedx_enrollment_allowed_request_body = $this->get_openedx_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ); - if ( 'user_exists' === $enrollment_allowed_request_body[0] ) { + if ( 'user_exists' === $openedx_enrollment_allowed_request_body[0] ) { return $this->request_handler( $enrollment_data, 'enrollment_process' ); } else { - return $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $enrollment_allowed_request_body, self::API_ENROLLMENT_ALLOWED, 'POST' ); + return $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $openedx_enrollment_allowed_request_body, self::API_ENROLLMENT_ALLOWED, 'POST' ); } } } elseif ( 'unenroll' === $request_type ) { @@ -173,36 +173,36 @@ public function request_handler( $enrollment_data, $enrollment_action ) { $request_with_email_body = $this->get_enrollment_process_body( $enrollment_data, true, $access_token_string, $enrollment_action ); return $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $request_with_email_body, self::API_ENROLLMENT, 'POST' ); - } elseif ( 'enrollment_allowed' === $enrollment_action ) { + } elseif ( 'openedx_enrollment_allowed' === $enrollment_action ) { - $enrollment_allowed_request_body = $this->get_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ); + $openedx_enrollment_allowed_request_body = $this->get_openedx_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ); - if ( 'user_exists' === $enrollment_allowed_request_body[0] ) { + if ( 'user_exists' === $openedx_enrollment_allowed_request_body[0] ) { return $this->request_handler( $enrollment_data, 'enrollment_process' ); } else { - return $this->unenroll_enrollment_allowed( $enrollment_data, $access_token_string, $enrollment_allowed_request_body ); + return $this->unenroll_openedx_enrollment_allowed( $enrollment_data, $access_token_string, $openedx_enrollment_allowed_request_body ); } - } elseif ( 'enrollment_force' === $enrollment_action ) { + } elseif ( 'openedx_enrollment_force' === $enrollment_action ) { $request_with_email_body = $this->get_enrollment_process_body( $enrollment_data, true, $access_token_string, $enrollment_action ); return $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $request_with_email_body, self::API_ENROLLMENT, 'POST' ); - } elseif ( 'enrollment_allowed_force' === $enrollment_action ) { + } elseif ( 'openedx_enrollment_allowed_force' === $enrollment_action ) { - $enrollment_allowed_request_body = $this->get_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ); + $openedx_enrollment_allowed_request_body = $this->get_openedx_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ); - if ( 'user_exists' === $enrollment_allowed_request_body[0] ) { + if ( 'user_exists' === $openedx_enrollment_allowed_request_body[0] ) { return $this->request_handler( $enrollment_data, 'enrollment_process' ); } else { - return $this->unenroll_enrollment_allowed( $enrollment_data, $access_token_string, $enrollment_allowed_request_body ); + return $this->unenroll_openedx_enrollment_allowed( $enrollment_data, $access_token_string, $openedx_enrollment_allowed_request_body ); } } } if ( 'enrollment_sync' === $enrollment_action ) { - $enrollment_email = $enrollment_data['enrollment_email']; - $course_id = $enrollment_data['enrollment_course_id']; - $user_exist = $this->check_if_user_exists( $enrollment_email, $access_token_string ); + $openedx_enrollment_email = $enrollment_data['openedx_enrollment_email']; + $course_id = $enrollment_data['openedx_enrollment_course_id']; + $user_exist = $this->check_if_user_exists( $openedx_enrollment_email, $access_token_string ); if ( 'success' === $user_exist[0] ) { $method = 'GET'; @@ -213,27 +213,27 @@ public function request_handler( $enrollment_data, $enrollment_action ) { return $this->enrollment_sync_request( self::API_SYNC_ENROLLMENT, $method, $body, $access_token_string, 'username' ); } else { - $get_enrollments_allowed = $this->get_user_enrollments_allowed( $enrollment_email, $access_token_string ); + $get_enrollments_allowed = $this->get_user_enrollments_allowed( $openedx_enrollment_email, $access_token_string ); if ( 'error' === $get_enrollments_allowed[0] ) { return $get_enrollments_allowed; } - $enrollments_allowed_data = json_decode( $get_enrollments_allowed[1], true ); - $course_exists = false; - $get_enrollment_allowed_response = array(); + $enrollments_allowed_data = json_decode( $get_enrollments_allowed[1], true ); + $course_exists = false; + $get_openedx_enrollment_allowed_response = array(); - foreach ( $enrollments_allowed_data as $enrollment_allowed ) { - if ( isset( $enrollment_allowed['course_id'] ) && $course_id === $enrollment_allowed['course_id'] ) { - $course_exists = true; - $get_enrollment_allowed_response[] = $enrollment_allowed; + foreach ( $enrollments_allowed_data as $openedx_enrollment_allowed ) { + if ( isset( $openedx_enrollment_allowed['course_id'] ) && $course_id === $openedx_enrollment_allowed['course_id'] ) { + $course_exists = true; + $get_openedx_enrollment_allowed_response[] = $openedx_enrollment_allowed; } } if ( true === $course_exists ) { - return array( 'success', wp_json_encode( $get_enrollment_allowed_response ) ); + return array( 'success', wp_json_encode( $get_openedx_enrollment_allowed_response ) ); } else { - return array( 'error', 'There are no enrollments allowed for the user ' . $enrollment_email . ' and course ' . $course_id ); + return array( 'error', 'There are no enrollments allowed for the user ' . $openedx_enrollment_email . ' and course ' . $course_id ); } } } @@ -283,31 +283,31 @@ public function enrollment_sync_request( $api_endpoint, $method, $body, $access_ * * @param string $enrollment_data The enrollment data. * @param string $access_token_string The access token. - * @param string $enrollment_allowed_request_body The enrollment allowed request body. + * @param string $openedx_enrollment_allowed_request_body The enrollment allowed request body. * @return array The response array. */ - public function unenroll_enrollment_allowed( $enrollment_data, $access_token_string, $enrollment_allowed_request_body ) { + public function unenroll_openedx_enrollment_allowed( $enrollment_data, $access_token_string, $openedx_enrollment_allowed_request_body ) { - $course_id = $enrollment_data['enrollment_course_id']; - $enrollment_email = $enrollment_data['enrollment_email']; - $get_enrollments_allowed = $this->get_user_enrollments_allowed( $enrollment_email, $access_token_string ); + $course_id = $enrollment_data['openedx_enrollment_course_id']; + $openedx_enrollment_email = $enrollment_data['openedx_enrollment_email']; + $get_enrollments_allowed = $this->get_user_enrollments_allowed( $openedx_enrollment_email, $access_token_string ); if ( 'error' === $get_enrollments_allowed[0] ) { return $get_enrollments_allowed; } - $user_enrollment_allowed_exists = $this->check_user_enrollment_allowed_exists( $get_enrollments_allowed, $course_id ); + $user_openedx_enrollment_allowed_exists = $this->check_user_openedx_enrollment_allowed_exists( $get_enrollments_allowed, $course_id ); - if ( $user_enrollment_allowed_exists ) { + if ( $user_openedx_enrollment_allowed_exists ) { - $response = $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $enrollment_allowed_request_body, self::API_ENROLLMENT_ALLOWED, 'DELETE' ); + $response = $this->process_enrollment_action( $enrollment_data, $enrollment_action, $access_token_string, $openedx_enrollment_allowed_request_body, self::API_ENROLLMENT_ALLOWED, 'DELETE' ); if ( 'success' === $response[0] ) { return array( 'success', wp_json_encode( 'User unenrolled successfully.' ) ); } else { return $response; } } else { - return array( 'error', 'An enrollment allowed with email ' . $enrollment_email . ' and course' . $course_id . " doesn't exists." ); + return array( 'error', 'An enrollment allowed with email ' . $openedx_enrollment_email . ' and course' . $course_id . " doesn't exists." ); } } /** @@ -327,8 +327,8 @@ public function request_response_handler( $response, $enrollment_data, $enrollme return $response; } elseif ( 'success' !== $response[0] ) { - if ( ( 'enrollment_allowed' === $enrollment_action || 'enrollment_allowed_force' === $enrollment_action ) ) { - return $this->enrollment_allowed_handler( $response, $enrollment_data, $enrollment_action, $access_token_string ); + if ( ( 'openedx_enrollment_allowed' === $enrollment_action || 'openedx_enrollment_allowed_force' === $enrollment_action ) ) { + return $this->openedx_enrollment_allowed_handler( $response, $enrollment_data, $enrollment_action, $access_token_string ); } else { return $this->response_or_request_with_username( $response, $enrollment_data, $enrollment_action, $access_token_string ); } @@ -357,7 +357,7 @@ public function response_or_request_with_username( $response, $enrollment_data, } /** - * This function, in case of enrollment action is enrollment_allowed, will check the status code. + * This function, in case of enrollment action is openedx_enrollment_allowed, will check the status code. * In case of 404, it will try to do the request with the user email to get the Open edX supported versions * for the enrollment allowed, if not, it will return the response. * @@ -367,7 +367,7 @@ public function response_or_request_with_username( $response, $enrollment_data, * @param string $access_token_string The access token. * @return array The response array. */ - public function enrollment_allowed_handler( $response, $enrollment_data, $enrollment_action, $access_token_string ) { + public function openedx_enrollment_allowed_handler( $response, $enrollment_data, $enrollment_action, $access_token_string ) { $http_404_not_found = '404'; $status_code = ''; @@ -413,13 +413,13 @@ public function get_enrollment_process_body( $enrollment_data, $use_old_endpoint $user_or_email = ''; $user_or_email_value = ''; - $course_id = $enrollment_data['enrollment_course_id']; - $course_mode = $enrollment_data['enrollment_mode']; - $request_type = $enrollment_data['enrollment_request_type']; + $course_id = $enrollment_data['openedx_enrollment_course_id']; + $course_mode = $enrollment_data['openedx_enrollment_mode']; + $request_type = $enrollment_data['openedx_enrollment_request_type']; if ( $use_old_endpoint ) { $user_or_email = 'user'; - $user_or_email_value = $this->check_if_user_exists( $enrollment_data['enrollment_email'], $access_token_string ); + $user_or_email_value = $this->check_if_user_exists( $enrollment_data['openedx_enrollment_email'], $access_token_string ); if ( 'error' === $user_or_email_value[0] ) { return $user_or_email_value; @@ -428,7 +428,7 @@ public function get_enrollment_process_body( $enrollment_data, $use_old_endpoint } } else { $user_or_email = 'email'; - $user_or_email_value = $enrollment_data['enrollment_email']; + $user_or_email_value = $enrollment_data['openedx_enrollment_email']; } $body = array( @@ -450,7 +450,7 @@ public function get_enrollment_process_body( $enrollment_data, $use_old_endpoint $body['is_active'] = false; } - if ( 'enrollment_force' === $enrollment_action ) { + if ( 'openedx_enrollment_force' === $enrollment_action ) { $body['force_enrollment'] = true; } @@ -465,24 +465,24 @@ public function get_enrollment_process_body( $enrollment_data, $use_old_endpoint * @param string $enrollment_action The enrollment action. * @return array The request body. */ - public function get_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ) { + public function get_openedx_enrollment_allowed_body( $enrollment_data, $access_token_string, $enrollment_action ) { - $course_id = $enrollment_data['enrollment_course_id']; - $enrollment_email = $enrollment_data['enrollment_email']; - $request_type = $enrollment_data['enrollment_request_type']; - $user_exist = $this->check_if_user_exists( $enrollment_email, $access_token_string ); + $course_id = $enrollment_data['openedx_enrollment_course_id']; + $openedx_enrollment_email = $enrollment_data['openedx_enrollment_email']; + $request_type = $enrollment_data['openedx_enrollment_request_type']; + $user_exist = $this->check_if_user_exists( $openedx_enrollment_email, $access_token_string ); if ( 'success' === $user_exist[0] ) { return array( 'user_exists', $user_exist[1] ); } $body = array( - 'email' => $enrollment_email, + 'email' => $openedx_enrollment_email, 'course_id' => $course_id, 'auto_enroll' => true, ); - if ( 'enrollment_allowed_force' === $enrollment_action ) { + if ( 'openedx_enrollment_allowed_force' === $enrollment_action ) { $body['force_enrollment'] = true; } @@ -539,13 +539,13 @@ public function enrollment_request_api_call( $api_endpoint, $method, $body, $acc * @param string $course_id The course id. * @return boolean If the user exists or not. */ - public function check_user_enrollment_allowed_exists( $get_enrollments_allowed, $course_id ) { + public function check_user_openedx_enrollment_allowed_exists( $get_enrollments_allowed, $course_id ) { $enrollments_allowed_data = json_decode( $get_enrollments_allowed[1], true ); $course_exists = false; - foreach ( $enrollments_allowed_data as $enrollment_allowed ) { - if ( isset( $enrollment_allowed['course_id'] ) && $course_id === $enrollment_allowed['course_id'] ) { + foreach ( $enrollments_allowed_data as $openedx_enrollment_allowed ) { + if ( isset( $openedx_enrollment_allowed['course_id'] ) && $course_id === $openedx_enrollment_allowed['course_id'] ) { $course_exists = true; break; } @@ -558,11 +558,11 @@ public function check_user_enrollment_allowed_exists( $get_enrollments_allowed, /** * This function get, for a specific user, the courses where the user is enrolled with enrollment allowed. * - * @param string $enrollment_email The user email. + * @param string $openedx_enrollment_email The user email. * @param string $access_token_string The access token. * @return array The response array. */ - public function get_user_enrollments_allowed( $enrollment_email, $access_token_string ) { + public function get_user_enrollments_allowed( $openedx_enrollment_email, $access_token_string ) { $domain = get_option( 'openedx-domain' ); @@ -577,7 +577,7 @@ public function get_user_enrollments_allowed( $enrollment_email, $access_token_s 'Content-Type' => 'application/json', ), 'query' => array( - 'email' => $enrollment_email, + 'email' => $openedx_enrollment_email, ), ), ); @@ -595,13 +595,13 @@ public function get_user_enrollments_allowed( $enrollment_email, $access_token_s /** * Check if a user exists in the Open edX platform using its email. * - * @param string $enrollment_email The user email. + * @param string $openedx_enrollment_email The user email. * @param string $access_token_string The access token. * @return array The response array. */ - public function check_if_user_exists( $enrollment_email, $access_token_string ) { + public function check_if_user_exists( $openedx_enrollment_email, $access_token_string ) { - $user = $this->get_user( $enrollment_email, $access_token_string ); + $user = $this->get_user( $openedx_enrollment_email, $access_token_string ); return $user; } diff --git a/includes/model/class-openedx-commerce-enrollment.php b/includes/model/class-openedx-commerce-enrollment.php index 0816501..2d23bac 100644 --- a/includes/model/class-openedx-commerce-enrollment.php +++ b/includes/model/class-openedx-commerce-enrollment.php @@ -10,12 +10,12 @@ * @since 1.0.0 */ -namespace App\model; +namespace OpenedXCommerce\model; -use App\model\Openedx_Commerce_Log; -use App\Openedx_Commerce; -use App\admin\Openedx_Commerce_Admin; -use App\model\Openedx_Commerce_Api_Calls; +use OpenedXCommerce\model\Openedx_Commerce_Log; +use OpenedXCommerce\Openedx_Commerce; +use OpenedXCommerce\admin\Openedx_Commerce_Admin; +use OpenedXCommerce\model\Openedx_Commerce_Api_Calls; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -231,44 +231,44 @@ public function save_action( $post_id, $post ) { $enrollment_arr = array(); $enrollment_action = ''; - if ( isset( $_POST['enrollment_course_id'] ) ) { - $enrollment_arr['enrollment_course_id'] = sanitize_text_field( wp_unslash( $_POST['enrollment_course_id'] ) ); + if ( isset( $_POST['openedx_enrollment_course_id'] ) ) { + $enrollment_arr['openedx_enrollment_course_id'] = sanitize_text_field( wp_unslash( $_POST['openedx_enrollment_course_id'] ) ); } else { - $enrollment_arr['enrollment_course_id'] = sanitize_text_field( wp_unslash( '' ) ); + $enrollment_arr['openedx_enrollment_course_id'] = sanitize_text_field( wp_unslash( '' ) ); } - if ( isset( $_POST['enrollment_email'] ) ) { - $enrollment_arr['enrollment_email'] = sanitize_text_field( wp_unslash( $_POST['enrollment_email'] ) ); + if ( isset( $_POST['openedx_enrollment_email'] ) ) { + $enrollment_arr['openedx_enrollment_email'] = sanitize_text_field( wp_unslash( $_POST['openedx_enrollment_email'] ) ); } else { - $enrollment_arr['enrollment_email'] = sanitize_text_field( wp_unslash( '' ) ); + $enrollment_arr['openedx_enrollment_email'] = sanitize_text_field( wp_unslash( '' ) ); } - if ( isset( $_POST['enrollment_mode'] ) ) { - $enrollment_arr['enrollment_mode'] = sanitize_text_field( wp_unslash( $_POST['enrollment_mode'] ) ); + if ( isset( $_POST['openedx_enrollment_mode'] ) ) { + $enrollment_arr['openedx_enrollment_mode'] = sanitize_text_field( wp_unslash( $_POST['openedx_enrollment_mode'] ) ); } else { - $enrollment_arr['enrollment_mode'] = sanitize_text_field( wp_unslash( '' ) ); + $enrollment_arr['openedx_enrollment_mode'] = sanitize_text_field( wp_unslash( '' ) ); } - if ( isset( $_POST['enrollment_request_type'] ) ) { - $enrollment_arr['enrollment_request_type'] = sanitize_text_field( wp_unslash( $_POST['enrollment_request_type'] ) ); + if ( isset( $_POST['openedx_enrollment_request_type'] ) ) { + $enrollment_arr['openedx_enrollment_request_type'] = sanitize_text_field( wp_unslash( $_POST['openedx_enrollment_request_type'] ) ); } else { - $enrollment_arr['enrollment_request_type'] = sanitize_text_field( wp_unslash( '' ) ); + $enrollment_arr['openedx_enrollment_request_type'] = sanitize_text_field( wp_unslash( '' ) ); } - if ( isset( $_POST['enrollment_order_id'] ) ) { - $enrollment_arr['enrollment_order_id'] = sanitize_text_field( wp_unslash( $_POST['enrollment_order_id'] ) ); + if ( isset( $_POST['openedx_enrollment_order_id'] ) ) { + $enrollment_arr['openedx_enrollment_order_id'] = sanitize_text_field( wp_unslash( $_POST['openedx_enrollment_order_id'] ) ); } else { - $enrollment_arr['enrollment_order_id'] = sanitize_text_field( wp_unslash( '' ) ); + $enrollment_arr['openedx_enrollment_order_id'] = sanitize_text_field( wp_unslash( '' ) ); } if ( isset( $_POST['enrollment_process'] ) ) { - if ( isset( $_POST['enrollment_force'] ) && isset( $_POST['enrollment_allowed'] ) ) { - $enrollment_action = 'enrollment_allowed_force'; - } elseif ( isset( $_POST['enrollment_force'] ) ) { - $enrollment_action = 'enrollment_force'; - } elseif ( isset( $_POST['enrollment_allowed'] ) ) { - $enrollment_action = 'enrollment_allowed'; + if ( isset( $_POST['openedx_enrollment_force'] ) && isset( $_POST['openedx_enrollment_allowed'] ) ) { + $enrollment_action = 'openedx_enrollment_allowed_force'; + } elseif ( isset( $_POST['openedx_enrollment_force'] ) ) { + $enrollment_action = 'openedx_enrollment_force'; + } elseif ( isset( $_POST['openedx_enrollment_allowed'] ) ) { + $enrollment_action = 'openedx_enrollment_allowed'; } else { $enrollment_action = 'enrollment_process'; } @@ -297,12 +297,12 @@ public function save_action( $post_id, $post ) { public function insert_new( $enrollment_arr, $enrollment_action = '', $order_id = null ) { $this->unregister_save_hook(); - $new_enrollment = array( + $openedx_new_enrollment = array( 'post_content' => 'Created automatically by woocommerce to fullfill an order.', 'post_type' => 'openedx_enrollment', ); - $post_id = wp_insert_post( $new_enrollment ); - $post = get_post( $post_id ); + $post_id = wp_insert_post( $openedx_new_enrollment ); + $post = get_post( $post_id ); $this->save_enrollment( $post, $enrollment_arr, $enrollment_action, $order_id ); return $post; @@ -341,9 +341,9 @@ public function save_enrollment( $post, $enrollment_arr, $enrollment_action, $or */ if ( - $old_data['enrollment_course_id'] !== $enrollment_data['enrollment_course_id'] - || $old_data['enrollment_email'] !== $enrollment_data['enrollment_email'] - || $old_data['enrollment_mode'] !== $enrollment_data['enrollment_mode'] + $old_data['openedx_enrollment_course_id'] !== $enrollment_data['openedx_enrollment_course_id'] + || $old_data['openedx_enrollment_email'] !== $enrollment_data['openedx_enrollment_email'] + || $old_data['openedx_enrollment_mode'] !== $enrollment_data['openedx_enrollment_mode'] ) { $this->update_post( $post_id ); } @@ -370,9 +370,9 @@ public function save_enrollment( $post, $enrollment_arr, $enrollment_action, $or */ public function is_enrollment_data_empty( $enrollment_data ) { if ( - ! $enrollment_data['enrollment_course_id'] - || ! $enrollment_data['enrollment_email'] - || ! $enrollment_data['enrollment_mode'] + ! $enrollment_data['openedx_enrollment_course_id'] + || ! $enrollment_data['openedx_enrollment_email'] + || ! $enrollment_data['openedx_enrollment_mode'] ) { return true; } @@ -387,19 +387,19 @@ public function is_enrollment_data_empty( $enrollment_data ) { public function prepare_enrollment_data( $post_id, $enrollment_arr ) { // Sanitize enrollment arr. - sanitize_text_field( $enrollment_arr['enrollment_course_id'] ); - sanitize_text_field( $enrollment_arr['enrollment_email'] ); - sanitize_text_field( $enrollment_arr['enrollment_mode'] ); - sanitize_text_field( $enrollment_arr['enrollment_request_type'] ); - sanitize_text_field( $enrollment_arr['enrollment_order_id'] ); + sanitize_text_field( $enrollment_arr['openedx_enrollment_course_id'] ); + sanitize_text_field( $enrollment_arr['openedx_enrollment_email'] ); + sanitize_text_field( $enrollment_arr['openedx_enrollment_mode'] ); + sanitize_text_field( $enrollment_arr['openedx_enrollment_request_type'] ); + sanitize_text_field( $enrollment_arr['openedx_enrollment_order_id'] ); // Array of old post metadata. $old_data_array = array( - 'enrollment_course_id' => get_post_meta( $post_id, 'course_id', true ), - 'enrollment_email' => get_post_meta( $post_id, 'email', true ), - 'enrollment_mode' => get_post_meta( $post_id, 'mode', true ), - 'enrollment_request_type' => get_post_meta( $post_id, 'enrollment_request_type', true ), - 'enrollment_order_id' => get_post_meta( $post_id, 'order_id', true ), + 'openedx_enrollment_course_id' => get_post_meta( $post_id, 'course_id', true ), + 'openedx_enrollment_email' => get_post_meta( $post_id, 'email', true ), + 'openedx_enrollment_mode' => get_post_meta( $post_id, 'mode', true ), + 'openedx_enrollment_request_type' => get_post_meta( $post_id, 'enrollment_request_type', true ), + 'openedx_enrollment_order_id' => get_post_meta( $post_id, 'order_id', true ), ); // Return both arrays. @@ -417,16 +417,16 @@ public function prepare_enrollment_data( $post_id, $enrollment_arr ) { */ public function update_enrollment_meta_data( $post_id, $enrollment_data ) { // Update the $post metadata. - update_post_meta( $post_id, 'course_id', $enrollment_data['enrollment_course_id'] ); - update_post_meta( $post_id, 'email', $enrollment_data['enrollment_email'] ); - update_post_meta( $post_id, 'mode', $enrollment_data['enrollment_mode'] ); - update_post_meta( $post_id, 'order_id', $enrollment_data['enrollment_order_id'] ); - update_post_meta( $post_id, 'enrollment_request_type', $enrollment_data['enrollment_request_type'] ); + update_post_meta( $post_id, 'course_id', $enrollment_data['openedx_enrollment_course_id'] ); + update_post_meta( $post_id, 'email', $enrollment_data['openedx_enrollment_email'] ); + update_post_meta( $post_id, 'mode', $enrollment_data['openedx_enrollment_mode'] ); + update_post_meta( $post_id, 'order_id', $enrollment_data['openedx_enrollment_order_id'] ); + update_post_meta( $post_id, 'enrollment_request_type', $enrollment_data['openedx_enrollment_request_type'] ); - if ( 'enroll' === $enrollment_data['enrollment_request_type'] ) { + if ( 'enroll' === $enrollment_data['openedx_enrollment_request_type'] ) { update_post_meta( $post_id, 'is_active', true ); } - if ( 'unenroll' === $enrollment_data['enrollment_request_type'] ) { + if ( 'unenroll' === $enrollment_data['openedx_enrollment_request_type'] ) { update_post_meta( $post_id, 'is_active', false ); } } @@ -439,13 +439,13 @@ public function update_enrollment_meta_data( $post_id, $enrollment_data ) { */ public function update_post( $post_id, $status = null ) { - $enrollment_course_id = get_post_meta( $post_id, 'course_id', true ); - $enrollment_email = get_post_meta( $post_id, 'email', true ); - $enrollment_mode = get_post_meta( $post_id, 'mode', true ); + $openedx_enrollment_course_id = get_post_meta( $post_id, 'course_id', true ); + $openedx_enrollment_email = get_post_meta( $post_id, 'email', true ); + $openedx_enrollment_mode = get_post_meta( $post_id, 'mode', true ); $post_update = array( 'ID' => $post_id, - 'post_title' => $enrollment_course_id . ' | ' . $enrollment_email . ' | Mode: ' . $enrollment_mode . ' | Status: ' . $status, + 'post_title' => $openedx_enrollment_course_id . ' | ' . $openedx_enrollment_email . ' | Mode: ' . $openedx_enrollment_mode . ' | Status: ' . $status, ); if ( $status ) { diff --git a/includes/model/class-openedx-commerce-log.php b/includes/model/class-openedx-commerce-log.php index c4543b4..ec219c0 100644 --- a/includes/model/class-openedx-commerce-log.php +++ b/includes/model/class-openedx-commerce-log.php @@ -9,7 +9,7 @@ * @since 1.4.0 */ -namespace App\model; +namespace OpenedXCommerce\model; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -53,7 +53,7 @@ public function create_change_log( $post_id, $old_data_array, $enrollment_arr, $ 'api_response' => $response, ); - if ( empty( $old_data_array['enrollment_course_id'] ) ) { + if ( empty( $old_data_array['openedx_enrollment_course_id'] ) ) { $log_data['object_status'] = 'Object Created'; $old_data_array = '--'; } else { @@ -122,14 +122,14 @@ public function get_logs( $post_id ) { foreach ( $logs as $log ) { if ( null !== json_decode( $log['api_response'], true ) ) { - $formatted_logs .= "
"; + $formatted_logs .= "
"; } else { - $formatted_logs .= "
"; + $formatted_logs .= "
"; } $formatted_logs .= 'API: ' . $log['api_response'] . '
'; $formatted_logs .= '
'; - $formatted_logs .= "
"; + $formatted_logs .= "
"; $formatted_logs .= 'Timestamp: ' . gmdate( 'd-m-Y H:i:s', strtotime( $log['mod_date'] ) ) . '
'; $formatted_logs .= 'User: ' . $log['user'] . '
'; $formatted_logs .= 'Action: ' . $log['action_name'] . '
'; diff --git a/includes/model/class-openedx-commerce-post-type.php b/includes/model/class-openedx-commerce-post-type.php index 2708b62..9d37a20 100644 --- a/includes/model/class-openedx-commerce-post-type.php +++ b/includes/model/class-openedx-commerce-post-type.php @@ -8,7 +8,7 @@ * @since 1.0.0 */ -namespace App\model; +namespace OpenedXCommerce\model; if ( ! defined( 'ABSPATH' ) ) { exit; diff --git a/openedx-commerce.php b/openedx-commerce.php index 26b98d9..4488189 100644 --- a/openedx-commerce.php +++ b/openedx-commerce.php @@ -18,9 +18,9 @@ * @wordpress-plugin */ -use App\Openedx_Commerce_Activator; -use App\Openedx_Commerce_Deactivator; -use App\Openedx_Commerce; +use OpenedXCommerce\Openedx_Commerce_Activator; +use OpenedXCommerce\Openedx_Commerce_Deactivator; +use OpenedXCommerce\Openedx_Commerce; // If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { diff --git a/public/class-openedx-commerce-public.php b/public/class-openedx-commerce-public.php index ee181ee..36cb691 100644 --- a/public/class-openedx-commerce-public.php +++ b/public/class-openedx-commerce-public.php @@ -9,7 +9,7 @@ * @subpackage Openedx_Commerce/public */ -namespace App\public; +namespace OpenedXCommerce\public; /** * The public-facing functionality of the plugin. diff --git a/test/class-enrollment-test.php b/test/class-enrollment-test.php index dfedd63..68664a2 100644 --- a/test/class-enrollment-test.php +++ b/test/class-enrollment-test.php @@ -6,11 +6,11 @@ * @subpackage openedx-commerce/tests */ -namespace App\tests; +namespace OpenedXCommerce\tests; -use App\model\Openedx_Commerce_Enrollment; -use App\model\Openedx_Commerce_Post_Type; -use App\admin\Openedx_Commerce_Admin; +use OpenedXCommerce\model\Openedx_Commerce_Enrollment; +use OpenedXCommerce\model\Openedx_Commerce_Post_Type; +use OpenedXCommerce\admin\Openedx_Commerce_Admin; use PHPUnit\Framework\TestCase; /** diff --git a/utils/openedx-utils.php b/utils/openedx-utils.php index 7388c83..ee6af00 100644 --- a/utils/openedx-utils.php +++ b/utils/openedx-utils.php @@ -6,7 +6,7 @@ * @since 1.6.0 */ -namespace App\utils; +namespace OpenedXCommerce\utils; /** * Enrollment Request mode options.
- @@ -112,33 +112,33 @@ public function render_enrollment_info_form( $post ) { } ?> > - ? - + ? +
- +
- ? - + ? +
- $label ) : ?> - ? - + ? +
- - ? - + ? +
- +
- ? - + ? +
- - - ? - + + + ? + - - - ? - + + + ? +