Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: operation logs for enrollment requests #17

Merged
merged 36 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
864b457
feat: operation logs for changes into post form
julianramirez2 Jul 30, 2023
90de839
fix: enrollment log for when post is created
julianramirez2 Jul 30, 2023
3a45aeb
fix: mayus fix in object created message
julianramirez2 Jul 30, 2023
207fab6
fix: deleted comment in spanish
julianramirez2 Jul 31, 2023
5d63b4e
fix: logs in desc order
julianramirez2 Jul 31, 2023
b4aded0
fix: phpcs in info form file
julianramirez2 Jul 31, 2023
4b2ac69
fix: phpcs in enrollment and plugin files
julianramirez2 Jul 31, 2023
6f8ccee
fix: phpcs fixes about spacing
julianramirez2 Jul 31, 2023
36e229e
fix: phpcs fixes
julianramirez2 Jul 31, 2023
dfd5f88
fix: phpcs fixes about number of characters
julianramirez2 Jul 31, 2023
6c110ec
fix: phpcs fixes
julianramirez2 Jul 31, 2023
2f2f6d9
fix: deleted general info field from form
julianramirez2 Jul 31, 2023
ba76b55
fix: enrollment request type in before object fixed
julianramirez2 Jul 31, 2023
a0bcef4
fix: small adjustments to logs box frontend
julianramirez2 Jul 31, 2023
e827629
fix: logs are displayed in ascending order
julianramirez2 Jul 31, 2023
6b932c7
fix: deleted title attribute from email input
julianramirez2 Jul 31, 2023
f4c6765
fix: post name comparison comment improved
julianramirez2 Jul 31, 2023
6a0fbf1
fix: spanish variable names fixed
julianramirez2 Jul 31, 2023
62af177
fix: enrollment logs working, deleted spanish comments
julianramirez2 Aug 1, 2023
9cc43b7
fix: scroll to the bottom without using js
julianramirez2 Aug 1, 2023
e5e5f95
refactor: move code from files to a new model for db management
julianramirez2 Aug 1, 2023
e5f2006
refactor: add try-catch blocks for errors handling
julianramirez2 Aug 1, 2023
baf8680
fix: logs table variable name in english
julianramirez2 Aug 1, 2023
a2d88ab
fix: enrollment array values sanitized before operation
julianramirez2 Aug 1, 2023
eb9c3c0
refactor: save enrollment code decoupled
julianramirez2 Aug 1, 2023
2aaa00d
fix: sanitize field without create a variable
julianramirez2 Aug 1, 2023
7b23de9
fix: end line in plugin logs file
julianramirez2 Aug 2, 2023
5f5f277
fix: added object_status field for new/modified indication
julianramirez2 Aug 2, 2023
ed76543
refactor: styles added to css file
julianramirez2 Aug 3, 2023
bf0e4a5
fix: improved if eval for post status
julianramirez2 Aug 3, 2023
3a0c0f0
fix: logs table renamed in english
julianramirez2 Aug 3, 2023
6e076f1
refactor: check main enrollment data decoupled
julianramirez2 Aug 3, 2023
e81dabc
fix: check enrollment data method call fixed
julianramirez2 Aug 3, 2023
4b0bec5
Merge branch 'main' into operation-logs
julianramirez2 Aug 3, 2023
ee3ca7b
refactor: added comments to new functions
julianramirez2 Aug 3, 2023
1434f15
fix: endline in css file
julianramirez2 Aug 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion admin/css/openedx-woocommerce-plugin-admin.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
/**
* All of the CSS for your admin-specific functionality should be
* included in this file.
*/
*/

#namediv{
padding: 50px 20px 50px 20px;
}

.logs_box {
max-width: 100%;
max-height: 477px;
border: 1px solid #ccc;
padding: 10px;
white-space: pre-wrap;
word-wrap: break-word;
overflow: auto;
display: flex;
flex-direction: column-reverse;
}

.log_entry {
background-color: #f2f2f2;
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}

.logs_box strong {
font-weight: bold;
}
114 changes: 64 additions & 50 deletions admin/views/Openedx_Woocommerce_Plugin_Enrollment_Info_Form.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace App\admin\views;
use App\model\Openedx_Woocommerce_Plugin_Log;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -17,6 +18,15 @@ class Openedx_Woocommerce_Plugin_Enrollment_Info_Form {
*/
public $post_type = 'openedx_enrollment';

/**
* The log manager.
*
* @var Openedx_Woocommerce_Plugin_Log
* @access private
* @since 1.1.1
*/
private $log_manager;

/**
* Constructor function.
*
Expand All @@ -27,6 +37,16 @@ class Openedx_Woocommerce_Plugin_Enrollment_Info_Form {
public function __construct( $enrollment_request ) {
$this->render_enrollment_info_form($enrollment_request);
$this->replace_admin_meta_boxes();
$this->register_log_manager();
}

/**
* Register log manager
*
* @return void
*/
public function register_log_manager() {
$this->log_manager = new Openedx_Woocommerce_Plugin_Log();
}

/**
Expand All @@ -51,6 +71,7 @@ public function render_enrollment_info_form( $post ) {
if (! $course_id && ! $email) {
$new_enrollment = true;
}

?>
<div id="namediv" class="postbox">
<h2 class="">Open edX enrollment request</h2>
Expand All @@ -68,12 +89,11 @@ public function render_enrollment_info_form( $post ) {
<tr>
<td class="first"><label>User Email</label></td>
<td>
<div style="width: 49%; display: inline-table;">
<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 style="width: 49%; display: inline-table;">
<input type="email"
id="openedx_enrollment_email"
name="enrollment_email"
value="<?php echo( $email ); ?>">
</div>
</td>
</tr>
Expand Down Expand Up @@ -121,7 +141,9 @@ public function render_enrollment_info_form( $post ) {
</td>
</tr>
<tr>
<td class="first"><label for="openedx_enrollment_is_active">Request Type</label></td>
<td class="first">
<label for="openedx_enrollment_is_active">Request Type</label>
</td>
<td>

<select id="openedx_enrollment_is_active" name="enrollment_request_type">
Expand Down Expand Up @@ -154,40 +176,39 @@ public function render_enrollment_info_form( $post ) {
</td>
</tr>

<tr>
<td class="first"><label>General Info</label></td>
<td>
<p>Edited:
<?php
if ( get_post_meta( $post_id, 'edited', true ) ) {
echo 'yes';
} else {
echo 'no';
}
?>
</p>
<p>Last edited: <?php echo( get_the_modified_time( '', $post_id ) . ' ' . get_the_modified_date( '', $post_id ) ); ?></p>
</td>
</tr>

<tr>
<td class="first"><label>Choose an Action</label></td>
<td>
<select name="enrollment_action" id="actions-select">
<option value="save_no_process"><?php esc_html_e( 'Save without processing', 'wp-edunext-marketing-site' ); ?></option>
<option value="enrollment_sync"><?php esc_html_e( 'Synchronize (pull information)', 'wp-edunext-marketing-site' ); ?></option>
<option value="enrollment_process" selected><?php esc_html_e( 'Process request', 'wp-edunext-marketing-site' ); ?></option>
<option value="enrollment_no_pre"><?php esc_html_e( 'Process no pre-enrollment', 'wp-edunext-marketing-site' ); ?></option>
<option value="enrollment_force"><?php esc_html_e( 'Process --force', 'wp-edunext-marketing-site' ); ?></option>
<option value="enrollment_no_pre_force"><?php esc_html_e( 'Process no pre-enrollment --force', 'wp-edunext-marketing-site' ); ?></option>
<option value="default" disabled selected hidden>
Select an option
</option>
<option value="save_no_process">
<?php esc_html_e('Save without processing', 'wp-edunext-marketing-site'); ?>
</option>
<option value="enrollment_sync">
<?php esc_html_e('Synchronize (pull information)', 'wp-edunext-marketing-site'); ?>
</option>
<option value="enrollment_process">
<?php esc_html_e('Process request', 'wp-edunext-marketing-site'); ?>
</option>
<option value="enrollment_no_pre">
<?php esc_html_e('Process no pre-enrollment', 'wp-edunext-marketing-site'); ?>
</option>
<option value="enrollment_force">
<?php esc_html_e('Process --force', 'wp-edunext-marketing-site'); ?>
</option>
<option value="enrollment_no_pre_force">
<?php esc_html_e('Process no pre-enrollment --force', 'wp-edunext-marketing-site'); ?>
</option>
</select>
</td>
</tr>

<tr>
<td class="first"><label>Create/Update Enrollment</label></td>
<td>
<button class="button save_order button-primary"><span><?php esc_html_e( 'Apply action', 'wp-edunext-marketing-site' ); ?></span></button>
<button class="button save_order button-primary"><span><?php esc_html_e('Apply action', 'wp-edunext-marketing-site'); ?></span></button>
</td>
</tr>
</tbody>
Expand All @@ -196,32 +217,25 @@ public function render_enrollment_info_form( $post ) {
</div>
<?php
}


/**
* Temporary function to get test logs for the logs box
*
* @return string Test logs
*/
public function get_logs() {
$logs = "Log 1\n";
$logs .= "Log 2\n";
$logs .= "Log 3\n";
$logs .= "No errors ocurred\n";
return $logs;
}


/**
* Renders the logs box for the edit post box
* Render logs box
*
* @return void
* @param WP_Post $post Current post object.
*/
public function render_logs_box() {
$logs = $this->get_logs();
public function render_logs_box($post) {
$post_id = $post->ID;
$logs = $this->log_manager->getLogs($post_id);
?>

<style>

</style>
<div class="logs_box">
<pre><?php echo esc_html( $logs ); ?></pre>
<?php echo $logs; ?>
</div>

<?php
}

Expand All @@ -233,7 +247,7 @@ public function render_logs_box() {
public function replace_admin_meta_boxes() {
remove_meta_box( 'submitdiv', $this->post_type, 'side' );

add_meta_box( 'openedx_enrollment_request_actions', 'Enrollment Operation Logs', array( $this, 'render_logs_box' ), $this->post_type, 'side', 'high' );
add_meta_box('openedx_enrollment_request_actions', 'Enrollment Operation Logs', array( $this, 'render_logs_box' ), $this->post_type, 'side', 'high');
}

}
3 changes: 3 additions & 0 deletions includes/Openedx_Woocommerce_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ private function load_dependencies() {
*/
include_once plugin_dir_path( dirname(__FILE__)) . 'includes/model/Openedx_Woocommerce_Plugin_Post_Type.php';

include_once plugin_dir_path( dirname(__FILE__)) . 'includes/model/Openedx_Woocommerce_Plugin_Logs.php';

/**
* The class responsible for rendering the enrollment info form
*/
Expand Down Expand Up @@ -182,6 +184,7 @@ private function define_admin_hooks() {
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
$this->loader->add_filter( 'gettext', $this, 'openedx_plugin_custom_post_message', 10, 3 );
$this->loader->wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . '../admin/css/openedx-woocommerce-plugin-admin.css', array(), $this->version, 'all' );

}

Expand Down
36 changes: 36 additions & 0 deletions includes/Openedx_Woocommerce_Plugin_Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Openedx_Woocommerce_Plugin_Loader {
*/
protected $filters;

protected $styles;

/**
* Initialize the collections used to maintain the actions and filters.
*
Expand All @@ -52,6 +54,7 @@ public function __construct() {

$this->actions = array();
$this->filters = array();
$this->styles = array();

}

Expand Down Expand Up @@ -83,6 +86,21 @@ public function add_filter( $hook, $component, $callback, $priority = 10, $accep
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}

/**
* Add a new style to the collection to be registered with WordPress.
*
* @since 1.1.1
* @param string $handle Name of the stylesheet. Should be unique.
* @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
* @param array $deps An array of registered stylesheet handles this stylesheet depends on.
* @param string $ver String specifying the stylesheet version number, if it has one. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the stylesheet.
* @param string $media The media for which this stylesheet has been defined.
* @return array The collection of actions and filters registered with WordPress.
*/
public function wp_enqueue_style( $handle, $src, $deps, $ver, $media ) {
$this->styles = $this->add_style($handle, $src, $deps, $ver, $media);
}

/**
* A utility function that is used to register the actions and hooks into a single
* collection.
Expand Down Expand Up @@ -111,6 +129,20 @@ private function add( $hooks, $hook, $component, $callback, $priority, $accepted

}

private function add_style( $handle, $src, $deps, $ver, $media ) {

$hooks[] = array(
'handle' => $handle,
'src' => $src,
'deps' => $deps,
'ver' => $ver,
'media' => $media
);

return $hooks;

}

/**
* Register the filters and actions with WordPress.
*
Expand All @@ -126,6 +158,10 @@ public function run() {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}

foreach ( $this->styles as $hook ) {
wp_enqueue_style( $hook['handle'], $hook['src'], $hook['deps'], $hook['ver'], $hook['media'] );
}

}

}
Loading