Skip to content

Commit

Permalink
BadgeOS achievement submission updated, ckeditor integration, bug fix…
Browse files Browse the repository at this point in the history
…: set -1 instead of 0 as default submission option, integration for group management, group filters support, interactive progress map support
  • Loading branch information
avi0007 committed May 22, 2016
1 parent f1e1513 commit 6423066
Show file tree
Hide file tree
Showing 14 changed files with 581 additions and 80 deletions.
17 changes: 15 additions & 2 deletions badgeos.php
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: http://www.badgeos.org/
* Description: BadgeOS lets your site’s users complete tasks and earn badges that recognize their achievement. Define achievements and choose from a range of options that determine when they're complete. Badges are Mozilla Open Badges (OBI) compatible through integration with the “Open Credit” API by Credly, the free web service for issuing, earning and sharing badges for lifelong achievement.
* Author: LearningTimes
* Version: 1.4.7
* Version: 1.4.8
* Author URI: https://credly.com/
* License: GNU AGPL
* Text Domain: badgeos
Expand Down Expand Up @@ -33,7 +33,7 @@ class BadgeOS {
*
* @var string
*/
public static $version = '1.4.7';
public static $version = '1.4.8';

function __construct() {
// Define plugin constants
Expand All @@ -59,6 +59,9 @@ function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_action( 'init', array( $this, 'credly_init' ) );

//add action for adding ckeditor script
add_action('wp_footer', 'wp_enqueue_scripts');

}

/**
Expand Down Expand Up @@ -282,6 +285,16 @@ function frontend_scripts() {
);
wp_localize_script( 'badgeos-achievements', 'BadgeosCredlyData', $data );

wp_enqueue_script(
'ck_editor_cdn',
('http://cdn.ckeditor.com/4.5.3/full/ckeditor.js'), false, null, false
);

wp_enqueue_script(
'custom_script',
plugins_url( '/js/ckeditor.js' , __FILE__ ),
false,null,true
);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions css/badgeos-front.css
Expand Up @@ -201,11 +201,19 @@ ul.badgeos-achievement-earners-list li {
border-radius: 5px;
margin-bottom:15px;
}

.badgeos-submission-comment-form{
width:100%;
}
.badgeos-submission-comment-form .badgeos-submission-comment {
width:100% !important;
}
.badgeos-submission-comment {
padding: 1em 1em 0;
margin-bottom: .5em;
overflow: hidden;
border-bottom: 1px dotted #aaa;
width: 600px !important;
}
.badgeos-submission-comment:last-child {
border-bottom:0;
Expand Down Expand Up @@ -233,3 +241,21 @@ ul.badgeos-achievement-earners-list li {
.badgeos-submission-comment-entry:last-child:after {
border: 0;
}

.badgeos-file-submission, .badgeos-submission-file{
margin: 8px 0;
}

.badgeos-feedback-filter select#group_id{
max-width:26% !important;
word-wrap: normal;
}

.badgeos_submission_message p{
background: #ffff00;
color: #333;
border-radius: 5px;
padding: 3px 10px;
text-align: center;

}
19 changes: 13 additions & 6 deletions css/badgeos-widgets.css
Expand Up @@ -8,19 +8,22 @@
min-height: 25px;
}
.widget-achievements-listing li.has-thumb {
min-height: 55px;
width: 100%;
float: left;
display: table;
}
.widget-achievements-listing .badgeos-item-thumb {
position: absolute;
top: 50%;
left: 0;
float: left;
display: table-cell;
vertical-align: middle;
}
.widget-achievements-listing .widget-badgeos-item-title {
font-weight: bold;
}
.widget-achievements-listing .has-thumb .widget-badgeos-item-title {
display: block;
text-indent: 60px;
width: 75%;
display: table-cell;
vertical-align: middle;
}
.share-credly {
position: relative;
Expand Down Expand Up @@ -112,3 +115,7 @@
.credly-wrap .success {
color: green;
}
.widget{
float:left;
width:100%;
}
4 changes: 2 additions & 2 deletions includes/achievement-functions.php
Expand Up @@ -260,10 +260,10 @@ function badgeos_is_achievement_sequential( $achievement_id = 0 ) {
*/
function badgeos_achievement_user_exceeded_max_earnings( $user_id = 0, $achievement_id = 0 ) {

$max_earnings = absint( get_post_meta( $achievement_id, '_badgeos_maximum_earnings', true ) );
$max_earnings = get_post_meta( $achievement_id, '_badgeos_maximum_earnings', true);

// If the badge has an earning limit, and we've earned it bdfore...
if ( $max_earnings && $user_has_badge = badgeos_get_user_achievements( array( 'user_id' => absint( $user_id ), 'achievement_id' => absint( $achievement_id ) ) ) ) {
if ( $max_earnings != -1 && $user_has_badge = badgeos_get_user_achievements( array( 'user_id' => absint( $user_id ), 'achievement_id' => absint( $achievement_id ) ) ) ) {
// If we've earned it as many (or more) times than allowed,
// then we have exceeded maximum earnings, thus true
if ( count( $user_has_badge ) >= $max_earnings ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/cmb/js/cmb.js
Expand Up @@ -198,7 +198,7 @@
.on( 'click', '.add-row-button', function(e) {

e.preventDefault();
self = $(this);
var self = $(this);

var tableselector = '#'+ self.data('selector');
var $table = $(tableselector);
Expand Down
6 changes: 3 additions & 3 deletions includes/content-filters.php
Expand Up @@ -613,7 +613,7 @@ function badgeos_render_submission( $submission = null, $args = array() ) {
$output = '<div class="badgeos-submission badgeos-feedback badgeos-feedback-' . $submission->ID . '">';

// Submission Title
$output .= '<h2>' . sprintf( __( 'Submission: "%1$s" (#%2$d)', 'badgeos' ), get_the_title( $achievement_id ), $submission->ID ) . '</h2>';
$output .= '<h2>' . sprintf( __( 'Submission: "%1$s"', 'badgeos' ), get_the_title( $achievement_id )) . '</h2>';
// Submission Meta
$output .= '<p class="badgeos-submission-meta">';
$output .= sprintf( '<strong class="label">%1$s</strong> <span class="badgeos-feedback-author">%2$s</span><br/>', __( 'Author:', 'badgeos' ), $display_name );
Expand All @@ -626,7 +626,7 @@ function badgeos_render_submission( $submission = null, $args = array() ) {

// Submission Content
$output .= '<div class="badgeos-submission-content">';
$output .= wpautop( $submission->post_content );
$output .= html_entity_decode( $submission->post_content , ENT_QUOTES, 'UTF-8' );
$output .= '</div>';

// Include any attachments
Expand Down Expand Up @@ -705,7 +705,7 @@ function badgeos_render_submission_comment( $comment = null, $odd_even = 'odd' )

// Content
$output .= '<div class="badgeos-comment-text">';
$output .= wpautop( $comment->comment_content );
$output .= html_entity_decode( wpautop( $comment->comment_content ), ENT_QUOTES, 'UTF-8' );
$output .= '</div>';

$output .= '</li><!-- badgeos-submission-comment -->';
Expand Down
14 changes: 13 additions & 1 deletion includes/meta-boxes.php
Expand Up @@ -125,7 +125,7 @@ function badgeos_custom_metaboxes( array $meta_boxes ) {
),
array(
'name' => __( 'Maximum Earnings', 'badgeos' ),
'desc' => ' '.__( 'Number of times a user can earn this badge (set to 0 for no maximum).', 'badgeos' ),
'desc' => ' '.__( 'Number of times a user can earn this badge (set to -1 for no maximum).', 'badgeos' ),
'id' => $prefix . 'maximum_earnings',
'type' => 'text_small',
'std' => '1',
Expand All @@ -140,6 +140,18 @@ function badgeos_custom_metaboxes( array $meta_boxes ) {
array( 'name' => __( 'Hidden to User', 'badgeos' ), 'value' => 'hidden', ),
),
),
array(
'name' => __( 'Allow Attachment for Submission', 'badgeos' ),
'desc' => ' '.__( 'Yes, allow to display submission attachment.', 'badgeos' ),
'id' => $prefix . 'all_attachment_submission',
'type' => 'checkbox',
),
array(
'name' => __( 'Allow Attachment for Submission Comment', 'badgeos' ),
'desc' => ' '.__( 'Yes, allow to display submission comment attachment.', 'badgeos' ),
'id' => $prefix . 'all_attachment_submission_comment',
'type' => 'checkbox',
),
), $prefix, $achievement_types )
), $achievement_types );

Expand Down
8 changes: 8 additions & 0 deletions includes/post-types.php
Expand Up @@ -225,6 +225,14 @@ function badgeos_register_achievement_type_cpt() {
// Determine whether this achievement type should be visible in the menu
$show_in_menu = get_post_meta( $achievement_type->ID, '_badgeos_show_in_menu', true ) ? 'badgeos_badgeos' : false;

//filter school admin menu badgeOS start
if(class_exists("BadgeOS_Group_Management") && function_exists('badgeos_get_user_role')){
$role = badgeos_get_user_role(get_current_user_id());
if(!empty($role) && ($role =="school_admin" || $role =="author")){
$show_in_menu=false;
}
}

// Register the post type
register_post_type( sanitize_title( substr( strtolower( $achievement_name_singular ), 0, 20 ) ), array(
'labels' => array(
Expand Down
5 changes: 3 additions & 2 deletions includes/rules-engine.php
Expand Up @@ -234,12 +234,13 @@ function badgeos_maybe_award_additional_achievements_to_user( $user_id = 0, $ach
// Get achievements that can be earned from completing this achievement
$dependent_achievements = badgeos_get_dependent_achievements( $achievement_id );

// See if a user has unlocked all achievements of a given type
badgeos_maybe_trigger_unlock_all( $user_id, $achievement_id );

// Loop through each dependent achievement and see if it can be awarded
foreach ( $dependent_achievements as $achievement )
badgeos_maybe_award_achievement_to_user( $achievement->ID, $user_id );

// See if a user has unlocked all achievements of a given type
badgeos_maybe_trigger_unlock_all( $user_id, $achievement_id );

}
add_action( 'badgeos_award_achievement', 'badgeos_maybe_award_additional_achievements_to_user', 10, 2 );
Expand Down
29 changes: 25 additions & 4 deletions includes/shortcodes/badgeos_submission.php
Expand Up @@ -48,13 +48,34 @@ function badgeos_submission_form( $atts = array() ) {
if ( isset( $_REQUEST['achievement_id'] ) && $_REQUEST['achievement_id'] == $atts['achievement_id'] ) {
// Don't award if this achievement was earned in the past 30 seconds
$recently_earned = badgeos_get_user_achievements( array( 'user_id' => get_current_user_id(), 'achievement_id' => $_REQUEST['achievement_id'], 'since' => ( time() - 30 ) ) );
if ( empty( $recently_earned ) ) {
if ( badgeos_save_submission_data() ) {
$output .= sprintf( '<p>%s</p>', __( 'Submission saved successfully.', 'badgeos' ) );

global $wp;
if ( empty( $recently_earned )) {
if ( badgeos_save_submission_data() ) {
$recent_submission_id = $_SESSION['new_added_submission_id'];
unset($_SESSION['new_added_submission_id']);
wp_redirect(home_url($wp->request.'?new_submission_id='.$recent_submission_id));
}
}
}else{
wp_redirect(home_url($wp->request));
}
}

if(!empty($_GET['new_submission_id']) && $new_submission_id = $_GET['new_submission_id']){
$posts = get_post( absint($new_submission_id) );
// Checking the type of submission and display the success message based on submission type
if($posts->post_status == 'draft'){
$output .= sprintf( '<div class="badgeos_submission_message"><p>%s</p></div>', __( 'Thank you! Your draft has been saved.', 'badgeos' ) );
}else {
if (get_post_meta($atts['achievement_id'], '_badgeos_earned_by', true) == 'submission') {

if(get_post_meta($new_submission_id , '_badgeos_submission_status', true) == 'pending')
$output .= sprintf('<div class="badgeos_submission_message"><p>%s</p></div>', __('Thank you! Your submission has been received.', 'badgeos'));

}
}
}

// If user has already submitted something, show their submissions
if ( badgeos_check_if_user_has_submission( get_current_user_id(), $atts['achievement_id'] ) ) {
$output .= badgeos_get_user_submissions( '', $atts['achievement_id'] );
Expand Down

0 comments on commit 6423066

Please sign in to comment.