Skip to content

Commit

Permalink
fix: improve namespace and variables naming (#65)
Browse files Browse the repository at this point in the history
* refactor: improve namespace naming

* refactor: add prefix to styles

* refactor: add prefix to forms and some variables

* fix: follow the phpcs conventions

* refactor: add openedx preffix to enrollment_order_id and enrollment_request_type
  • Loading branch information
MaferMazu authored Dec 20, 2023
1 parent 24e76a1 commit 9f4493d
Show file tree
Hide file tree
Showing 18 changed files with 212 additions and 212 deletions.
26 changes: 13 additions & 13 deletions admin/class-openedx-commerce-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 = '<td>';
$html_output .= '<input style="height:30px;" type="text" name="order_id_input' . esc_attr( $item_id ) . '" value="' . esc_attr( $input_value ) . '" pattern="\d*" />';
$html_output .= '<input style="height:30px;" type="text" name="openedx_order_id_input' . esc_attr( $item_id ) . '" value="' . esc_attr( $input_value ) . '" pattern="\d*" />';
$html_output .= '<a href="' . $order_url . '" class="button" style="margin-left: 5px; vertical-align: bottom;' . ( $input_value ? '' : 'pointer-events: none; opacity: 0.6;' ) . '">View Request</a>';
$html_output .= '</td>';

Expand Down Expand Up @@ -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 );
}
}
Expand Down Expand Up @@ -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 );
Expand Down
18 changes: 9 additions & 9 deletions admin/css/class-openedx-commerce-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* included in this file.
*/

.logs_box {
.openedx_logs_box {
max-width: 100%;
max-height: 477px;
border: 1px solid #ccc;
Expand All @@ -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;
}

Expand All @@ -48,7 +48,7 @@
flex: 1;
}

#generate-jwt-token {
#openedx-generate-jwt-token {
margin-left: 10px;
}

Expand Down Expand Up @@ -87,7 +87,7 @@
float: right;
}

.tooltip-icon {
.openedx-tooltip-icon {
font-size: 13px;
color: white;
position: relative;
Expand All @@ -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;
Expand All @@ -113,7 +113,7 @@
margin-left: 5px;
}

.tooltip-icon:hover + .tooltip-text {
.openedx-tooltip-icon:hover + .openedx-tooltip-text {
display: inline-block;
}

Expand Down
64 changes: 32 additions & 32 deletions admin/views/class-openedx-commerce-enrollment-info-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,23 +87,23 @@ 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;
}

?>
<div id="namediv" class="postbox">

<fieldset>
<h2 class="">Open edX enrollment request</h2>
<input type="hidden" name="new_enrollment" value="<?php echo wp_kses( $new_enrollment, array( 'true', 'false' ) ); ?>">
<input type="hidden" name="openedx_new_enrollment" value="<?php echo wp_kses( $openedx_new_enrollment, array( 'true', 'false' ) ); ?>">
<table class="form-table">
<tbody>
<tr>
<td class="first"><label for="openedx_enrollment_course_id">Course ID</label></td>
<td>
<input type="text" id="openedx_enrollment_course_id" name="enrollment_course_id" value="<?php echo esc_attr( $course_id ); ?>"
<input type="text" id="openedx_enrollment_course_id" name="openedx_enrollment_course_id" value="<?php echo esc_attr( $course_id ); ?>"
<?php
if ( '' !== $course_id ) {
?>
Expand All @@ -112,33 +112,33 @@ public function render_enrollment_info_form( $post ) {
}
?>
>
<span class="tooltip-icon">?</span>
<span class="tooltip-text"><?php esc_html_e( 'The id of the course to be used for the enroll, e.g. course-v1:edX+DemoX+Demo_Course.', 'wp-openedx-commerce' ); ?></span>
<span class="openedx-tooltip-icon">?</span>
<span class="openedx-tooltip-text"><?php esc_html_e( 'The id of the course to be used for the enroll, e.g. course-v1:edX+DemoX+Demo_Course.', 'wp-openedx-commerce' ); ?></span>
</td>
</tr>
<tr>
<td class="first"><label>User Email</label></td>
<td>
<div style="width: 20%; display: inline-table;">
<input type="email" id="openedx_enrollment_email" name="enrollment_email" value="<?php echo esc_attr( $email ); ?>">
<input type="email" id="openedx_enrollment_email" name="openedx_enrollment_email" value="<?php echo esc_attr( $email ); ?>">
</div>
<span class="tooltip-icon">?</span>
<span class="tooltip-text"><?php esc_html_e( 'The email of the user to be used for the enroll.', 'wp-openedx-commerce' ); ?></span>
<span class="openedx-tooltip-icon">?</span>
<span class="openedx-tooltip-text"><?php esc_html_e( 'The email of the user to be used for the enroll.', 'wp-openedx-commerce' ); ?></span>
<button name="enrollment_sync" class="button save_order button-secondary sync_button"><span><?php esc_html_e( 'Read from Open edX', 'wp-openedx-commerce' ); ?></span></button>
</td>
</tr>
<tr class="gray_zone first_zone">
<td class="first"><label for="openedx_enrollment_mode">Course Mode</label></td>
<td>
<select id="openedx_enrollment_mode" name="enrollment_mode">
<select id="openedx_enrollment_mode" name="openedx_enrollment_mode">
<?php foreach ( $mode_options as $value => $label ) : ?>
<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $mode, $value ); ?>>
<?php echo esc_html( $label ); ?>
</option>
<?php endforeach; ?>
</select>
<span class="tooltip-icon">?</span>
<span class="tooltip-text"><?php esc_html_e( 'The mode of your enrollment request. Make sure to set a mode that your course has.', 'wp-openedx-commerce' ); ?></span>
<span class="openedx-tooltip-icon">?</span>
<span class="openedx-tooltip-text"><?php esc_html_e( 'The mode of your enrollment request. Make sure to set a mode that your course has.', 'wp-openedx-commerce' ); ?></span>
</td>
</tr>

Expand All @@ -148,10 +148,10 @@ public function render_enrollment_info_form( $post ) {
</td>
<td>

<select id="openedx_enrollment_is_active" name="enrollment_request_type">
<select id="openedx_enrollment_is_active" name="openedx_enrollment_request_type">
<option value="enroll"
<?php
if ( $is_active || $new_enrollment ) {
if ( $is_active || $openedx_new_enrollment ) {
echo ( 'selected="selected"' );
}
?>
Expand All @@ -162,7 +162,7 @@ public function render_enrollment_info_form( $post ) {
</option>
<option value="unenroll"
<?php
if ( ! $is_active && ! $new_enrollment ) {
if ( ! $is_active && ! $openedx_new_enrollment ) {
echo ( 'selected="selected"' );
}
?>
Expand All @@ -172,15 +172,15 @@ public function render_enrollment_info_form( $post ) {
?>
</option>
</select>
<span class="tooltip-icon">?</span>
<span class="tooltip-text"><?php esc_html_e( 'The type of your request. If you select Enroll, you will create an enrollment, and if you select Un-enroll, you will set a soft unenrollment (enrollment with status inactive).', 'wp-openedx-commerce' ); ?></span>
<span class="openedx-tooltip-icon">?</span>
<span class="openedx-tooltip-text"><?php esc_html_e( 'The type of your request. If you select Enroll, you will create an enrollment, and if you select Un-enroll, you will set a soft unenrollment (enrollment with status inactive).', 'wp-openedx-commerce' ); ?></span>
</td>
</tr>
<tr class="gray_zone">
<td class="first"><label for="openedx_enrollment_order_id">WC Order ID</label></td>
<td>
<div style="width: 18.5%; display: inline-table;">
<input type="text" id="openedx_enrollment_order_id" name="enrollment_order_id" value="<?php echo esc_attr( $order_id ); ?>" pattern="\d*" />
<input type="text" id="openedx_enrollment_order_id" name="openedx_enrollment_order_id" value="<?php echo esc_attr( $order_id ); ?>" pattern="\d*" />
</div>
<div style="width: 6%; display: inline-table;">
<?php
Expand All @@ -191,23 +191,23 @@ public function render_enrollment_info_form( $post ) {
}
?>
</div>
<span class="tooltip-icon">?</span>
<span class="tooltip-text"><?php esc_html_e( 'The id of the order associated with this request.', 'wp-openedx-commerce' ); ?></span>
<span class="openedx-tooltip-icon">?</span>
<span class="openedx-tooltip-text"><?php esc_html_e( 'The id of the order associated with this request.', 'wp-openedx-commerce' ); ?></span>
</td>
</tr>

<tr class="gray_zone">
<td class="checkbox-td">
<input class="action-checkbox" type="checkbox" id="force" name="enrollment_force" value="opcion1">
<label for="force"><?php esc_html_e( 'Use the "force" flag', 'wp-openedx-commerce' ); ?></label>
<span class="tooltip-icon">?</span>
<span class="tooltip-text"><?php esc_html_e( "Disregard the course's enrollment end dates.", 'wp-openedx-commerce' ); ?></span>
<input class="action-checkbox" type="checkbox" id="openedx_enrollment_force" name="openedx_enrollment_force" value="openedx_force">
<label for="openedx_enrollment_force"><?php esc_html_e( 'Use the "force" flag', 'wp-openedx-commerce' ); ?></label>
<span class="openedx-tooltip-icon">?</span>
<span class="openedx-tooltip-text"><?php esc_html_e( "Disregard the course's enrollment end dates.", 'wp-openedx-commerce' ); ?></span>
</td>
<td>
<input class="action-checkbox" type="checkbox" id="no_pre" name="enrollment_allowed" value="opcion1">
<label for="no_pre"><?php esc_html_e( "Create course enrollment allowed if the user doesn't exist", 'wp-openedx-commerce' ); ?></label>
<span class="tooltip-icon">?</span>
<span class="tooltip-text"><?php esc_html_e( 'Creates a register in the table Course Enrollment Allowed if the email we use in the request is not a user in our Open edX platform yet.', 'wp-openedx-commerce' ); ?></span>
<input class="action-checkbox" type="checkbox" id="openedx_enrollment_allowed" name="openedx_enrollment_allowed" value="openedx_allowed">
<label for="openedx_enrollment_allowed"><?php esc_html_e( "Create course enrollment allowed if the user doesn't exist", 'wp-openedx-commerce' ); ?></label>
<span class="openedx-tooltip-icon">?</span>
<span class="openedx-tooltip-text"><?php esc_html_e( 'Creates a register in the table Course Enrollment Allowed if the email we use in the request is not a user in our Open edX platform yet.', 'wp-openedx-commerce' ); ?></span>
</td>
</tr>

Expand Down Expand Up @@ -245,7 +245,7 @@ public function render_logs_box( $post ) {
<style>

</style>
<div class="logs_box">
<div class="openedx_logs_box">
<?php
echo wp_kses(
$logs,
Expand Down
6 changes: 3 additions & 3 deletions admin/views/class-openedx-commerce-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* @since 1.6.0
*/

namespace App\admin\views;
namespace OpenedXCommerce\admin\views;

use App\model\Openedx_Commerce_Api_Calls;
use OpenedXCommerce\model\Openedx_Commerce_Api_Calls;
use DateTime;
use DateInterval;

Expand Down Expand Up @@ -293,7 +293,7 @@ public function openedx_jwt_token_callback() {
<input class="setting_input" class="openedx-jwt-token-input" type="text" value="<?php echo esc_attr( $masked_value ); ?>" readonly/>

<form method="post">
<button class="button" type="submit" name="generate_new_token" id="generate-jwt-token">Generate JWT Token</button>
<button class="button" type="submit" name="generate_new_token" id="openedx-generate-jwt-token">Generate JWT Token</button>
</form>


Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion includes/class-openedx-commerce-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @subpackage Openedx_Commerce/includes
*/

namespace App;
namespace OpenedXCommerce;

/**
* Fired during plugin activation.
Expand Down
2 changes: 1 addition & 1 deletion includes/class-openedx-commerce-deactivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @subpackage Openedx_Commerce/includes
*/

namespace App;
namespace OpenedXCommerce;

/**
* Fired during plugin deactivation.
Expand Down
2 changes: 1 addition & 1 deletion includes/class-openedx-commerce-i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @subpackage Openedx_Commerce/includes
*/

namespace App;
namespace OpenedXCommerce;

/**
* Define the internationalization functionality.
Expand Down
2 changes: 1 addition & 1 deletion includes/class-openedx-commerce-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @subpackage Openedx_Commerce/includes
*/

namespace App;
namespace OpenedXCommerce;

/**
* Register all actions and filters for the plugin.
Expand Down
10 changes: 5 additions & 5 deletions includes/class-openedx-commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* @author eduNEXT <[email protected]>
*/

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.
Expand Down
Loading

0 comments on commit 9f4493d

Please sign in to comment.