Skip to content

Commit

Permalink
fix: enrollment crud operations working correctly (#15)
Browse files Browse the repository at this point in the history
* fix: crud saving information and allowing to modify it

* fix: checking the POST variables exist in the form

* fix: all enrollment form fields can be changed

* refactor: api code cleanup

* fix: deleted email form field

* fix: update request title when updating name, course id or mode

* fix: update post method name updated based on its functionality

* fix: revert email field and remove username field

* fix: phpcs requirements in admin file

* fix: fixed number of characters and deleted unused line
  • Loading branch information
julianramirez2 authored Jul 21, 2023
1 parent 80b95a1 commit ab972ec
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 395 deletions.
96 changes: 47 additions & 49 deletions admin/Openedx_Woocommerce_Plugin_Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,27 @@ class Openedx_Woocommerce_Plugin_Admin {
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
* @param string $test Flag variable to know if it is a test.
*/
public function __construct( $plugin_name, $version, $test = null) {
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
* @param string $test Flag variable to know if it is a test.
*/
public function __construct( $plugin_name, $version, $test = null) {

$this->plugin_name = $plugin_name;
$this->version = $version;
if(!$test){
$this->createEnrollmentClass();
}

}

/**
* Create an instance of the Openedx_Woocommerce_Plugin_Enrollment class.
*
* @since 1.0.0
*/
public function createEnrollmentClass() {

if( !$test ) {
$this->createEnrollmentClass();
}
}

/**
* Create an instance of the Openedx_Woocommerce_Plugin_Enrollment class.
*
* @since 1.0.0
*/
public function createEnrollmentClass() {

$this->openedx_enrollment = new Openedx_Woocommerce_Plugin_Enrollment( $this );

}
Expand Down Expand Up @@ -109,32 +108,32 @@ public function enqueue_styles() {
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
* @since 1.0.0
*
* @return void
*/
public function enqueue_scripts() {

/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Openedx_Woocommerce_Plugin_Loader as all of the hooks are defined
* in that particular class.
* defined in Openedx_Woocommerce_Plugin_Loader as
* all of the hooks are defined in that particular class.
*
* The Openedx_Woocommerce_Plugin_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/

//wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/openedx-woocommerce-plugin-admin.js', array( 'jquery' ), $this->version, false );


}

/**
* Register Enrollment Request custom post type
*
* @since 1.0.0
*/
public function register_enrollment_custom_post_type() {
/**
* Register Enrollment Request custom post type
*
* @since 1.0.0
*/
public function register_enrollment_custom_post_type() {

$this->openedx_enrollment->register_enrollment_custom_post_type();

Expand All @@ -145,9 +144,9 @@ public function register_enrollment_custom_post_type() {
*
* @since 1.0.0
*/
public function render_enrollment_info_form() {
public function render_enrollment_info_form($post) {

$this->openedx_enrollment_info_form = new Openedx_Woocommerce_Plugin_Enrollment_Info_Form($this->openedx_enrollment);
$this->openedx_enrollment_info_form = new Openedx_Woocommerce_Plugin_Enrollment_Info_Form($post);

}

Expand All @@ -166,26 +165,25 @@ public function register_post_type( $post_type = '', $plural = '', $single = '',
return;
}

$post_type = $this->createPostType( $post_type, $plural, $single, $description, $options );
$post_type = $this->createPostType($post_type, $plural, $single, $description, $options);

return $post_type;

}

/**
* Create a new instance of the Openedx_Woocommerce_Plugin_Post_Type class and register a new post type.
*
* @param string $post_type Post type name.
* @param string $plural Post type item plural name.
* @param string $single Post type item single name.
* @param string $description Description of the post type.
* @param array $options Additional options for the post type.
* @return object Post type class object.
*/
public function createPostType($post_type = '', $plural = '', $single = '', $description = '', $options = array()) {

return new Openedx_Woocommerce_Plugin_Post_Type( $post_type, $plural, $single, $description, $options );
/**
* Create a new instance of the Openedx_Woocommerce_Plugin_Post_Type class and register a new post type.
*
* @param string $post_type Post type name.
* @param string $plural Post type item plural name.
* @param string $single Post type item single name.
* @param string $description Description of the post type.
* @param array $options Additional options for the post type.
* @return object Post type class object.
*/
public function createPostType($post_type = '', $plural = '', $single = '', $description = '', $options = array()) {

}
return new Openedx_Woocommerce_Plugin_Post_Type($post_type, $plural, $single, $description, $options);

}
}
31 changes: 6 additions & 25 deletions admin/views/Openedx_Woocommerce_Plugin_Enrollment_Info_Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ public function render_enrollment_info_form( $post ) {

$course_id = get_post_meta( $post_id, 'course_id', true );
$email = get_post_meta( $post_id, 'email', true );
$username = get_post_meta( $post_id, 'username', true );
$mode = get_post_meta( $post_id, 'mode', true );
$is_active = get_post_meta( $post_id, 'is_active', true );
$order_id = get_post_meta( $post_id, 'order_id', true );

$new_enrollment = false;
if ( ! $course_id && ! $email && ! $username ) {
if ( ! $course_id && ! $email ) {
$new_enrollment = true;
}
?>
Expand All @@ -63,35 +62,17 @@ public function render_enrollment_info_form( $post ) {
<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"
<?php
if ( ! $new_enrollment ) {
echo( ' readonly' );}
?>
value="<?php echo( $course_id ); ?>">
</td>
</tr>
<tr>
<td class="first"><label>User</label></td>
<td>
<div style="width: 49%; display: inline-table;">
<label for="openedx_enrollment_username">Username:</label>
<input type="text" id="openedx_enrollment_username" name="enrollment_username"
title="You only need to fill one. Either the email or username"
<?php
if ( ! $new_enrollment ) {
echo( ' readonly' );}
?>
value="<?php echo( $username ); ?>">
</div>
<div style="width: 49%; display: inline-table;">
<label for="openedx_enrollment_email">Email:</label>
<input type="email" id="openedx_enrollment_email" name="enrollment_email"
<?php
if ( ! $new_enrollment ) {
echo( ' readonly' );}
?>
title="You only need to fill one. Either the email or username"
value="<?php echo( $email ); ?>">
<div style="width: 49%; display: inline-table;">
<label for="openedx_enrollment_email">Email:</label>
<input type="email" id="openedx_enrollment_email" name="enrollment_email"
title="You only need to fill one. Either the email or username"
value="<?php echo( $email ); ?>">
</div>
</td>
</tr>
Expand Down
Loading

0 comments on commit ab972ec

Please sign in to comment.