adding quiz and course completion notifications, fixing the post type display for...
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 30 Jul 2018 14:50:02 +0000 (10:50 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 30 Jul 2018 14:50:02 +0000 (10:50 -0400)
assets/badge.png [new file with mode: 0644]
content-single.php
footer.php
functions.php
glm-dev/scss/_badge.scss [new file with mode: 0644]
glm-dev/scss/glm-dev.scss
single.php

diff --git a/assets/badge.png b/assets/badge.png
new file mode 100644 (file)
index 0000000..f1b9848
Binary files /dev/null and b/assets/badge.png differ
index cf2abf4..1466166 100644 (file)
@@ -4,6 +4,7 @@
  */
 global $post;
 $pt = $post->post_type;
+$ld_types = array('sfwd-courses','sfwd-lesses','sfwd-quiz');
 $post_date = of_get_option('post_date');
 $post_footer = of_get_option('post_footer');
 $post_date_class = ((!empty($post_date) && $post_date == ' ') || has_post_thumbnail()) ? " no-date" : "";
@@ -18,11 +19,11 @@ $lesson_content = $lessons_page->post_content;
                        <img src="<?php echo esc_url($image[0]); ?>" alt="<?php echo esc_attr(get_the_title()); ?>"> 
                </div>
                <?php endif; 
-                $class = ($pt === 'cmvl_channel') ? 'cmvl-title' : "basic-title";
+                $class = ($pt === 'sfwd-courses') ? 'cmvl-title' : "basic-title";
         ?>
                <h1 class="entry-title<?php echo esc_attr($post_date_class); ?> <?php echo $class; ?>"><?php the_title(); ?></h1>
 
-        <?php if( $pt !== 'cmvl_channel'){ ?>
+        <?php if( !in_array($pt, $ld_types) ){ ?>
             <div class="entry-meta">
                 <?php accesspress_parallax_posted_on(); ?>
             </div><!-- .entry-meta -->
@@ -30,7 +31,7 @@ $lesson_content = $lessons_page->post_content;
        </header><!-- .entry-header -->
 
        <div class="entry-content">
-        <?php if( $pt === 'cmvl_channel'){ ?>
+        <?php if( $pt === 'sfwd-courses'){ ?>
             <p> <?php echo $lesson_content; ?> </p>
         <?php } ?>
                <?php the_content(); ?>
index 8dd715b..8fc92b0 100644 (file)
 <div id="go-top"><a href="#page"><i class="fa fa-angle-up"></i></a></div>
 
 <?php wp_footer(); ?>
+<div class="glm-badge-alert" id="quiz-badge">
+               <div style="position: relative;background: #3D3D3D;" id="glm-quiz-passed">
+                       <img style="float: left;" src="<?php echo get_template_directory_uri(); ?>/assets/badge.png" alt="" />
+                       <span> You've passed the quiz </span>
+                       <div style="clear: both;"> </div>
+               </div>
+       </div>
+       <div class="glm-badge-alert" id="course-badge">
+               <div style="position: relative;background: #3D3D3D;" id="glm-course-passed">
+                       <img style="float: left;" src="<?php echo get_template_directory_uri(); ?>/assets/badge.png" alt="" />
+                       <span> You've passed the quiz </span>
+                       <div style="clear: both;"> </div>
+               </div>
+       </div>
+       <script>
+               (function(open) {
+                       const $ = jQuery;
+                       XMLHttpRequest.prototype.open = function() {
+                               this.addEventListener("readystatechange", function() {
+                                       if( this.response.includes('quiz_finished') && this.readyState === 4 ){
+                                               let data = JSON.parse(this.response);
+                                               if(data.pass === 1){
+                                                       setTimeout(function(){
+                                                               $(".glm-badge-alert#quiz-badge").fadeIn("fast");
+                                                               $(".glm-badge-alert#quiz-badge").addClass("shake");
+                                                       }, 1500)
+                                                       setTimeout(function(){
+                                                               $(".glm-badge-alert#quiz-badge").fadeOut("slow");
+                                                       }, 10000)
+                                               }
+                    }
+                    if( this.response.includes('course_finished') && this.readyState === 4 ){
+                                               let data = JSON.parse(this.response);
+                                               if(data.pass === 1){
+                                                       setTimeout(function(){
+                                                               $(".glm-badge-alert#course-badge").fadeIn("fast");
+                                                               $(".glm-badge-alert#course-badge").addClass("shake");
+                                                       }, 1500)
+                                                       setTimeout(function(){
+                                                               $(".glm-badge-alert#course-badge").fadeOut("slow");
+                                                       }, 10000)
+                                               }
+                                       }
+                               }, false);
+                               open.apply(this, arguments);
+                       };
+               })(XMLHttpRequest.prototype.open);
 </body>
 </html>
\ No newline at end of file
index cac1ad3..17dba00 100644 (file)
@@ -288,4 +288,14 @@ function displaydate(){
     return date('l, F t, Y');
 }
 add_shortcode( 'date', 'displaydate' );
-add_filter( 'show_admin_bar', '__return_false' );
\ No newline at end of file
+add_filter( 'show_admin_bar', '__return_false' );
+add_action("learndash_quiz_completed", function($data) {
+       $data["quiz_finished"] = "yes";
+       echo json_encode($data);
+       wp_die();
+}, 5, 1);
+add_action("learndash_course_completed", function($data) {
+       $finished["quiz_finished"] = "yes";
+       echo json_encode($finished);
+       wp_die();
+}, 5, 1);
\ No newline at end of file
diff --git a/glm-dev/scss/_badge.scss b/glm-dev/scss/_badge.scss
new file mode 100644 (file)
index 0000000..afadcc3
--- /dev/null
@@ -0,0 +1,51 @@
+body{
+    .glm-badge-alert#quiz-badge{
+        &:hover{
+            cursor: pointer;
+        }
+        display: none;
+        width: 300px;
+        position: absolute;
+        top: 25px;
+        right: 10px;
+        z-index: 999;
+        img{
+            max-width: 75px;
+        }
+        span{
+            font-size: 18px;
+            position: absolute;
+            top: 50%;
+            transform: translateY(-50%);
+            color:white;
+            left: 90px;
+        }
+        img:hover {
+            /* Start the shake animation and make the animation last for 0.5 seconds */
+            animation: shake 0.5s; 
+            /* When the animation is finished, start again */
+            animation-iteration-count: infinite; 
+        }
+        
+        @keyframes shake {
+            10%, 90% {
+              transform: translate3d(-2px, 0, 0);
+            }
+          
+            20%, 80% {
+              transform: translate3d(3px, 0, 0);
+            }
+          
+            30%, 50%, 70% {
+              transform: translate3d(-5px, 0, 0);
+            }
+          
+            40%, 60% {
+              transform: translate3d(5px, 0, 0);
+            }
+          }
+    }
+}
+.shake{
+    animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
+}
\ No newline at end of file
index cc587de..32f7402 100644 (file)
@@ -1,2 +1,3 @@
 @import 'video-lessons';
 @import 'body';
+@import 'badge';
index 09271f9..0bd2ae3 100644 (file)
@@ -6,7 +6,9 @@
  */
 global $post;
 $pt = $post->post_type;
-if($pt === 'cmvl_channel'){
+$title = $post->post_name;
+$ld_types = array('sfwd-courses','sfwd-lessons','sfwd-quiz');
+if(in_array($pt, $ld_types)){
     $fw = 'full-width';
 }else {
     $fw = false;
@@ -14,18 +16,15 @@ if($pt === 'cmvl_channel'){
 get_header(); ?>
 <div class="mid-content clearfix">
     <div id="primary" class="content-area <?php echo $fw; ?>">
-    <?php if($pt === 'cmvl_channel'){ ?>
-        <a href="<?php echo get_permalink(363); ?>">Back to my courses</a>
         
-    <?php } ?>
-   
                <main id="main" class="site-main" role="main">
         
                <?php while ( have_posts() ) : the_post(); ?>
 
                        <?php get_template_part( 'content', 'single' ); 
-
-            if($pt !== 'cmvl_channel'){
+           
+            if(!in_array($pt, $ld_types)){
+                
                 $post_pagination = of_get_option('post_pagination');
                 if( $post_pagination == 1 || !isset($post_pagination)) :
                 the_post_navigation( array(
@@ -47,7 +46,7 @@ get_header(); ?>
        </div><!-- #primary -->
 
 <?php 
-    if($pt !== "cmvl_channel"){
+    if(!in_array($pt, $ld_types)){
         get_sidebar(); 
     }
 ?>