@@ -25,167 +25,167 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | class Sensei_Shortcode_User_Courses implements Sensei_Shortcode_Interface { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var WP_Query to help setup the query needed by the render method. |
|
| 30 | - */ |
|
| 31 | - protected $query; |
|
| 28 | + /** |
|
| 29 | + * @var WP_Query to help setup the query needed by the render method. |
|
| 30 | + */ |
|
| 31 | + protected $query; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var string number of items to show on the current page |
|
| 35 | - * Default: -1. |
|
| 36 | - */ |
|
| 37 | - protected $number; |
|
| 33 | + /** |
|
| 34 | + * @var string number of items to show on the current page |
|
| 35 | + * Default: -1. |
|
| 36 | + */ |
|
| 37 | + protected $number; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var string ordery by course field |
|
| 41 | - * Default: date |
|
| 42 | - */ |
|
| 43 | - protected $orderby; |
|
| 39 | + /** |
|
| 40 | + * @var string ordery by course field |
|
| 41 | + * Default: date |
|
| 42 | + */ |
|
| 43 | + protected $orderby; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string ASC or DESC |
|
| 47 | - * Default: 'DESC' |
|
| 48 | - */ |
|
| 49 | - protected $order; |
|
| 45 | + /** |
|
| 46 | + * @var string ASC or DESC |
|
| 47 | + * Default: 'DESC' |
|
| 48 | + */ |
|
| 49 | + protected $order; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var status can be completed or active. If none is specified all will be shown |
|
| 53 | - */ |
|
| 54 | - protected $status; |
|
| 51 | + /** |
|
| 52 | + * @var status can be completed or active. If none is specified all will be shown |
|
| 53 | + */ |
|
| 54 | + protected $status; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Setup the shortcode object |
|
| 58 | - * |
|
| 59 | - * @since 1.9.0 |
|
| 60 | - * @param array $attributes |
|
| 61 | - * @param string $content |
|
| 62 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 63 | - */ |
|
| 64 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 56 | + /** |
|
| 57 | + * Setup the shortcode object |
|
| 58 | + * |
|
| 59 | + * @since 1.9.0 |
|
| 60 | + * @param array $attributes |
|
| 61 | + * @param string $content |
|
| 62 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 63 | + */ |
|
| 64 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 65 | 65 | |
| 66 | - if(! is_user_logged_in() ) { |
|
| 67 | - // show the login form |
|
| 68 | - Sensei()->frontend->sensei_login_form(); |
|
| 69 | - return; |
|
| 70 | - } |
|
| 66 | + if(! is_user_logged_in() ) { |
|
| 67 | + // show the login form |
|
| 68 | + Sensei()->frontend->sensei_login_form(); |
|
| 69 | + return; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // set up all argument need for constructing the course query |
|
| 73 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 74 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 75 | - $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all'; |
|
| 72 | + // set up all argument need for constructing the course query |
|
| 73 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 74 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 75 | + $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all'; |
|
| 76 | 76 | |
| 77 | - // set the default for menu_order to be ASC |
|
| 78 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 77 | + // set the default for menu_order to be ASC |
|
| 78 | + if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 79 | 79 | |
| 80 | - $this->order = 'ASC'; |
|
| 80 | + $this->order = 'ASC'; |
|
| 81 | 81 | |
| 82 | - }else{ |
|
| 82 | + }else{ |
|
| 83 | 83 | |
| 84 | - // for everything else use the value passed or the default DESC |
|
| 85 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 84 | + // for everything else use the value passed or the default DESC |
|
| 85 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 86 | 86 | |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - // setup the course query that will be used when rendering |
|
| 90 | - $this->setup_course_query(); |
|
| 91 | - } |
|
| 89 | + // setup the course query that will be used when rendering |
|
| 90 | + $this->setup_course_query(); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Sets up the object course query |
|
| 95 | - * that will be used in the render method. |
|
| 96 | - * |
|
| 97 | - * @since 1.9.0 |
|
| 98 | - */ |
|
| 99 | - protected function setup_course_query(){ |
|
| 93 | + /** |
|
| 94 | + * Sets up the object course query |
|
| 95 | + * that will be used in the render method. |
|
| 96 | + * |
|
| 97 | + * @since 1.9.0 |
|
| 98 | + */ |
|
| 99 | + protected function setup_course_query(){ |
|
| 100 | 100 | |
| 101 | - $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' ); |
|
| 102 | - $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true ); |
|
| 103 | - if ( !is_array($user_courses_logs) ) { |
|
| 101 | + $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' ); |
|
| 102 | + $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true ); |
|
| 103 | + if ( !is_array($user_courses_logs) ) { |
|
| 104 | 104 | |
| 105 | - $user_courses_logs = array( $user_courses_logs ); |
|
| 105 | + $user_courses_logs = array( $user_courses_logs ); |
|
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - $completed_ids = $active_ids = array(); |
|
| 110 | - foreach( $user_courses_logs as $course_status ) { |
|
| 109 | + $completed_ids = $active_ids = array(); |
|
| 110 | + foreach( $user_courses_logs as $course_status ) { |
|
| 111 | 111 | |
| 112 | - if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) { |
|
| 112 | + if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) { |
|
| 113 | 113 | |
| 114 | - $completed_ids[] = $course_status->comment_post_ID; |
|
| 114 | + $completed_ids[] = $course_status->comment_post_ID; |
|
| 115 | 115 | |
| 116 | - } else { |
|
| 116 | + } else { |
|
| 117 | 117 | |
| 118 | - $active_ids[] = $course_status->comment_post_ID; |
|
| 118 | + $active_ids[] = $course_status->comment_post_ID; |
|
| 119 | 119 | |
| 120 | - } |
|
| 121 | - } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - if( 'completed' == $this->status ){ |
|
| 123 | + if( 'completed' == $this->status ){ |
|
| 124 | 124 | |
| 125 | - $included_courses = $completed_ids; |
|
| 125 | + $included_courses = $completed_ids; |
|
| 126 | 126 | |
| 127 | 127 | |
| 128 | - }elseif( 'active'==$this->status ){ |
|
| 128 | + }elseif( 'active'==$this->status ){ |
|
| 129 | 129 | |
| 130 | - $included_courses = $active_ids; |
|
| 130 | + $included_courses = $active_ids; |
|
| 131 | 131 | |
| 132 | - }else{ // all courses |
|
| 132 | + }else{ // all courses |
|
| 133 | 133 | |
| 134 | - if( empty( $completed_ids ) ){ |
|
| 134 | + if( empty( $completed_ids ) ){ |
|
| 135 | 135 | |
| 136 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) ); |
|
| 137 | - } |
|
| 136 | + add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) ); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if( empty( $active_ids ) ){ |
|
| 139 | + if( empty( $active_ids ) ){ |
|
| 140 | 140 | |
| 141 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) ); |
|
| 141 | + add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) ); |
|
| 142 | 142 | |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if( empty( $completed_ids ) && empty( $active_ids ) ){ |
|
| 145 | + if( empty( $completed_ids ) && empty( $active_ids ) ){ |
|
| 146 | 146 | |
| 147 | - $included_courses = array('-1000'); // don't show any courses |
|
| 147 | + $included_courses = array('-1000'); // don't show any courses |
|
| 148 | 148 | |
| 149 | - }else{ |
|
| 150 | - $included_courses = Sensei_Utils::array_zip_merge( (array)$active_ids, (array)$completed_ids ); |
|
| 151 | - } |
|
| 149 | + }else{ |
|
| 150 | + $included_courses = Sensei_Utils::array_zip_merge( (array)$active_ids, (array)$completed_ids ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // temporary work around to hide pagination on the courses page |
|
| 157 | + // this is in place until we can load the course for each tab via ajax |
|
| 158 | + // if the shortcode is not active or in active and the active and completed |
|
| 159 | + // tabs show up. |
|
| 160 | + $number_of_posts = $this->number; |
|
| 161 | + if( 'active' != $this->status && 'complete' != $this->status ){ |
|
| 162 | + $number_of_posts = 1000; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // course query parameters |
|
| 166 | + $query_var_paged = get_query_var('paged'); |
|
| 167 | + $query_args = array( |
|
| 168 | + 'post_type' => 'course', |
|
| 169 | + 'post_status' => 'publish', |
|
| 170 | + 'orderby' => $this->orderby, |
|
| 171 | + 'order' => $this->order, |
|
| 172 | + 'paged' => empty( $query_var_paged )? 1 : $query_var_paged, |
|
| 173 | + 'posts_per_page' => $number_of_posts, |
|
| 174 | + 'post__in' => $included_courses, |
|
| 175 | + ); |
|
| 176 | + |
|
| 177 | + $this->query = new WP_Query( $query_args ); |
|
| 152 | 178 | |
| 179 | + }// end setup _course_query |
|
| 153 | 180 | |
| 154 | - } |
|
| 155 | - |
|
| 156 | - // temporary work around to hide pagination on the courses page |
|
| 157 | - // this is in place until we can load the course for each tab via ajax |
|
| 158 | - // if the shortcode is not active or in active and the active and completed |
|
| 159 | - // tabs show up. |
|
| 160 | - $number_of_posts = $this->number; |
|
| 161 | - if( 'active' != $this->status && 'complete' != $this->status ){ |
|
| 162 | - $number_of_posts = 1000; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // course query parameters |
|
| 166 | - $query_var_paged = get_query_var('paged'); |
|
| 167 | - $query_args = array( |
|
| 168 | - 'post_type' => 'course', |
|
| 169 | - 'post_status' => 'publish', |
|
| 170 | - 'orderby' => $this->orderby, |
|
| 171 | - 'order' => $this->order, |
|
| 172 | - 'paged' => empty( $query_var_paged )? 1 : $query_var_paged, |
|
| 173 | - 'posts_per_page' => $number_of_posts, |
|
| 174 | - 'post__in' => $included_courses, |
|
| 175 | - ); |
|
| 176 | - |
|
| 177 | - $this->query = new WP_Query( $query_args ); |
|
| 178 | - |
|
| 179 | - }// end setup _course_query |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Output the message that tells the user they have |
|
| 183 | - * no completed courses. |
|
| 184 | - * |
|
| 185 | - * @since 1.9.0 |
|
| 186 | - */ |
|
| 187 | - public function completed_no_course_message_output(){ |
|
| 188 | - ?> |
|
| 181 | + /** |
|
| 182 | + * Output the message that tells the user they have |
|
| 183 | + * no completed courses. |
|
| 184 | + * |
|
| 185 | + * @since 1.9.0 |
|
| 186 | + */ |
|
| 187 | + public function completed_no_course_message_output(){ |
|
| 188 | + ?> |
|
| 189 | 189 | <li class="user-completed"> |
| 190 | 190 | <div class="sensei-message info"> |
| 191 | 191 | |
@@ -194,16 +194,16 @@ discard block |
||
| 194 | 194 | </div> |
| 195 | 195 | </li> |
| 196 | 196 | <?php |
| 197 | - } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * Output the message that tells the user they have |
|
| 201 | - * no active courses. |
|
| 202 | - * |
|
| 203 | - * @since 1.9.0 |
|
| 204 | - */ |
|
| 205 | - public function active_no_course_message_output(){ |
|
| 206 | - ?> |
|
| 199 | + /** |
|
| 200 | + * Output the message that tells the user they have |
|
| 201 | + * no active courses. |
|
| 202 | + * |
|
| 203 | + * @since 1.9.0 |
|
| 204 | + */ |
|
| 205 | + public function active_no_course_message_output(){ |
|
| 206 | + ?> |
|
| 207 | 207 | |
| 208 | 208 | <li class="user-active"> |
| 209 | 209 | <div class="sensei-message info"> |
@@ -219,141 +219,141 @@ discard block |
||
| 219 | 219 | </div> |
| 220 | 220 | </li> |
| 221 | 221 | <?php |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Rendering the shortcode this class is responsible for. |
|
| 226 | - * |
|
| 227 | - * @return string $content |
|
| 228 | - */ |
|
| 229 | - public function render(){ |
|
| 224 | + /** |
|
| 225 | + * Rendering the shortcode this class is responsible for. |
|
| 226 | + * |
|
| 227 | + * @return string $content |
|
| 228 | + */ |
|
| 229 | + public function render(){ |
|
| 230 | 230 | |
| 231 | - global $wp_query; |
|
| 231 | + global $wp_query; |
|
| 232 | 232 | |
| 233 | - if(! is_user_logged_in() ) { |
|
| 234 | - return ''; |
|
| 235 | - } |
|
| 233 | + if(! is_user_logged_in() ) { |
|
| 234 | + return ''; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - // keep a reference to old query |
|
| 238 | - $current_global_query = $wp_query; |
|
| 237 | + // keep a reference to old query |
|
| 238 | + $current_global_query = $wp_query; |
|
| 239 | 239 | |
| 240 | - // assign the query setup in $this-> setup_course_query |
|
| 241 | - $wp_query = $this->query; |
|
| 240 | + // assign the query setup in $this-> setup_course_query |
|
| 241 | + $wp_query = $this->query; |
|
| 242 | 242 | |
| 243 | - $this->attach_shortcode_hooks(); |
|
| 243 | + $this->attach_shortcode_hooks(); |
|
| 244 | 244 | |
| 245 | - ob_start(); |
|
| 246 | - echo '<section id="sensei-user-courses">'; |
|
| 247 | - Sensei_Messages::the_my_messages_link(); |
|
| 248 | - Sensei_Templates::get_template('loop-course.php'); |
|
| 249 | - Sensei_Templates::get_template('globals/pagination.php'); |
|
| 250 | - echo '</section>'; |
|
| 245 | + ob_start(); |
|
| 246 | + echo '<section id="sensei-user-courses">'; |
|
| 247 | + Sensei_Messages::the_my_messages_link(); |
|
| 248 | + Sensei_Templates::get_template('loop-course.php'); |
|
| 249 | + Sensei_Templates::get_template('globals/pagination.php'); |
|
| 250 | + echo '</section>'; |
|
| 251 | 251 | |
| 252 | - $shortcode_output = ob_get_clean(); |
|
| 252 | + $shortcode_output = ob_get_clean(); |
|
| 253 | 253 | |
| 254 | - $this->detach_shortcode_hooks(); |
|
| 254 | + $this->detach_shortcode_hooks(); |
|
| 255 | 255 | |
| 256 | - //restore old query |
|
| 257 | - $wp_query = $current_global_query; |
|
| 256 | + //restore old query |
|
| 257 | + $wp_query = $current_global_query; |
|
| 258 | 258 | |
| 259 | - return $shortcode_output; |
|
| 259 | + return $shortcode_output; |
|
| 260 | 260 | |
| 261 | - }// end render |
|
| 261 | + }// end render |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Add hooks for the shortcode |
|
| 265 | - * |
|
| 266 | - * @since 1.9.0 |
|
| 267 | - */ |
|
| 268 | - public function attach_shortcode_hooks(){ |
|
| 263 | + /** |
|
| 264 | + * Add hooks for the shortcode |
|
| 265 | + * |
|
| 266 | + * @since 1.9.0 |
|
| 267 | + */ |
|
| 268 | + public function attach_shortcode_hooks(){ |
|
| 269 | 269 | |
| 270 | - // attach the toggle functionality |
|
| 271 | - // don't show the toggle action if the user specified complete or active for this shortcode |
|
| 272 | - if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){ |
|
| 270 | + // attach the toggle functionality |
|
| 271 | + // don't show the toggle action if the user specified complete or active for this shortcode |
|
| 272 | + if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){ |
|
| 273 | 273 | |
| 274 | - add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 275 | - add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 ); |
|
| 274 | + add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 275 | + add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 ); |
|
| 276 | 276 | |
| 277 | - } |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - // add extra classes to distinguish the course based on user completed or active |
|
| 280 | - add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 279 | + // add extra classes to distinguish the course based on user completed or active |
|
| 280 | + add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 281 | 281 | |
| 282 | - // attach progress meter below course |
|
| 283 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 284 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 282 | + // attach progress meter below course |
|
| 283 | + add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 284 | + add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 285 | 285 | |
| 286 | - } |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * Remove hooks for the shortcode |
|
| 290 | - * |
|
| 291 | - * @since 1.9.0 |
|
| 292 | - */ |
|
| 293 | - public function detach_shortcode_hooks(){ |
|
| 288 | + /** |
|
| 289 | + * Remove hooks for the shortcode |
|
| 290 | + * |
|
| 291 | + * @since 1.9.0 |
|
| 292 | + */ |
|
| 293 | + public function detach_shortcode_hooks(){ |
|
| 294 | 294 | |
| 295 | - //remove all hooks after the output is generated |
|
| 296 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 297 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 298 | - remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 299 | - remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 300 | - } |
|
| 295 | + //remove all hooks after the output is generated |
|
| 296 | + remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 297 | + remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 298 | + remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 299 | + remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Hooks into sensei_course_content_inside_after |
|
| 304 | - * |
|
| 305 | - * @param $course |
|
| 306 | - */ |
|
| 307 | - public function attach_course_progress( $course_id ){ |
|
| 302 | + /** |
|
| 303 | + * Hooks into sensei_course_content_inside_after |
|
| 304 | + * |
|
| 305 | + * @param $course |
|
| 306 | + */ |
|
| 307 | + public function attach_course_progress( $course_id ){ |
|
| 308 | 308 | |
| 309 | - $percentage = Sensei()->course->get_completion_percentage( $course_id, get_current_user_id() ); |
|
| 310 | - echo Sensei()->course->get_progress_meter( $percentage ); |
|
| 309 | + $percentage = Sensei()->course->get_completion_percentage( $course_id, get_current_user_id() ); |
|
| 310 | + echo Sensei()->course->get_progress_meter( $percentage ); |
|
| 311 | 311 | |
| 312 | - }// attach_course_progress |
|
| 312 | + }// attach_course_progress |
|
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Hooked into sensei_course_content_inside_after |
|
| 317 | - * |
|
| 318 | - * Prints out the course action buttons |
|
| 319 | - * |
|
| 320 | - * @param integer $course_id |
|
| 321 | - */ |
|
| 322 | - public function attach_course_buttons( $course_id ){ |
|
| 315 | + /** |
|
| 316 | + * Hooked into sensei_course_content_inside_after |
|
| 317 | + * |
|
| 318 | + * Prints out the course action buttons |
|
| 319 | + * |
|
| 320 | + * @param integer $course_id |
|
| 321 | + */ |
|
| 322 | + public function attach_course_buttons( $course_id ){ |
|
| 323 | 323 | |
| 324 | - Sensei()->course->the_course_action_buttons( get_post( $course_id ) ); |
|
| 324 | + Sensei()->course->the_course_action_buttons( get_post( $course_id ) ); |
|
| 325 | 325 | |
| 326 | - }// attach_course_buttons |
|
| 326 | + }// attach_course_buttons |
|
| 327 | 327 | |
| 328 | - /** |
|
| 329 | - * Add a the user status class for the given course. |
|
| 330 | - * |
|
| 331 | - * @since 1.9 |
|
| 332 | - * |
|
| 333 | - * @param array $classes |
|
| 334 | - * @param WP_Post $course |
|
| 335 | - * @return array $classes |
|
| 336 | - */ |
|
| 337 | - public function course_status_class_tagging($classes, $course){ |
|
| 328 | + /** |
|
| 329 | + * Add a the user status class for the given course. |
|
| 330 | + * |
|
| 331 | + * @since 1.9 |
|
| 332 | + * |
|
| 333 | + * @param array $classes |
|
| 334 | + * @param WP_Post $course |
|
| 335 | + * @return array $classes |
|
| 336 | + */ |
|
| 337 | + public function course_status_class_tagging($classes, $course){ |
|
| 338 | 338 | |
| 339 | - if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) { |
|
| 339 | + if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) { |
|
| 340 | 340 | |
| 341 | - $classes[] = 'user-completed'; |
|
| 341 | + $classes[] = 'user-completed'; |
|
| 342 | 342 | |
| 343 | - } else { |
|
| 343 | + } else { |
|
| 344 | 344 | |
| 345 | - $classes[] = 'user-active'; |
|
| 345 | + $classes[] = 'user-active'; |
|
| 346 | 346 | |
| 347 | - } |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - return $classes; |
|
| 349 | + return $classes; |
|
| 350 | 350 | |
| 351 | - }// end course_status_class_tagging |
|
| 351 | + }// end course_status_class_tagging |
|
| 352 | 352 | |
| 353 | - /** |
|
| 354 | - * Output the course toggle functionality |
|
| 355 | - */ |
|
| 356 | - public function course_toggle_actions(){ ?> |
|
| 353 | + /** |
|
| 354 | + * Output the course toggle functionality |
|
| 355 | + */ |
|
| 356 | + public function course_toggle_actions(){ ?> |
|
| 357 | 357 | |
| 358 | 358 | <section id="user-course-status-toggle"> |
| 359 | 359 | <a id="sensei-user-courses-active-action" href=""><?php _e('Active Courses'); ?></a> |
@@ -363,12 +363,12 @@ discard block |
||
| 363 | 363 | |
| 364 | 364 | <?php } |
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * Load the javascript for the toggle functionality |
|
| 368 | - * |
|
| 369 | - * @since 1.9.0 |
|
| 370 | - */ |
|
| 371 | - function print_course_toggle_actions_inline_script() { ?> |
|
| 366 | + /** |
|
| 367 | + * Load the javascript for the toggle functionality |
|
| 368 | + * |
|
| 369 | + * @since 1.9.0 |
|
| 370 | + */ |
|
| 371 | + function print_course_toggle_actions_inline_script() { ?> |
|
| 372 | 372 | |
| 373 | 373 | <script type="text/javascript"> |
| 374 | 374 | var buttonContainer = jQuery('#user-course-status-toggle'); |
@@ -24,69 +24,69 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function __construct ( $file = __FILE__ ) { |
| 26 | 26 | $this->file = $file; |
| 27 | - $this->token = 'quiz'; |
|
| 27 | + $this->token = 'quiz'; |
|
| 28 | 28 | $this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' ); |
| 29 | 29 | add_action( 'save_post', array( $this, 'update_author' )); |
| 30 | 30 | |
| 31 | 31 | // listen to the reset button click |
| 32 | 32 | add_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
| 33 | 33 | |
| 34 | - // fire the complete quiz button submit for grading action |
|
| 35 | - add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 34 | + // fire the complete quiz button submit for grading action |
|
| 35 | + add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_quiz_submit_listener' ) ); |
|
| 36 | 36 | |
| 37 | 37 | // fire the save user answers quiz button click responder |
| 38 | 38 | add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_save_quiz_answers_listener' ) ); |
| 39 | 39 | |
| 40 | - // fire the load global data function |
|
| 41 | - add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 40 | + // fire the load global data function |
|
| 41 | + add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'load_global_quiz_data' ), 80 ); |
|
| 42 | 42 | |
| 43 | - add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 43 | + add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') ); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - } // End __construct() |
|
| 46 | + } // End __construct() |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Update the quiz author when the lesson post type is save |
|
| 50 | - * |
|
| 51 | - * @param int $post_id |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 49 | + * Update the quiz author when the lesson post type is save |
|
| 50 | + * |
|
| 51 | + * @param int $post_id |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | 54 | public function update_author( $post_id ){ |
| 55 | 55 | |
| 56 | 56 | // If this isn't a 'lesson' post, don't update it. |
| 57 | - // if this is a revision don't save it |
|
| 58 | - if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 59 | - || wp_is_post_revision( $post_id ) ) { |
|
| 57 | + // if this is a revision don't save it |
|
| 58 | + if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type'] |
|
| 59 | + || wp_is_post_revision( $post_id ) ) { |
|
| 60 | 60 | |
| 61 | - return; |
|
| 61 | + return; |
|
| 62 | 62 | |
| 63 | - } |
|
| 64 | - // get the lesson author id to be use late |
|
| 65 | - $saved_post = get_post( $post_id ); |
|
| 66 | - $new_lesson_author_id = $saved_post->post_author; |
|
| 63 | + } |
|
| 64 | + // get the lesson author id to be use late |
|
| 65 | + $saved_post = get_post( $post_id ); |
|
| 66 | + $new_lesson_author_id = $saved_post->post_author; |
|
| 67 | 67 | |
| 68 | - //get the lessons quiz |
|
| 68 | + //get the lessons quiz |
|
| 69 | 69 | $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id ); |
| 70 | - foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 70 | + foreach ( (array) $lesson_quizzes as $quiz_item ) { |
|
| 71 | 71 | |
| 72 | - if( ! $quiz_item ) { |
|
| 73 | - continue; |
|
| 74 | - } |
|
| 72 | + if( ! $quiz_item ) { |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // setup the quiz items new author value |
|
| 76 | + // setup the quiz items new author value |
|
| 77 | 77 | $my_post = array( |
| 78 | - 'ID' => $quiz_item, |
|
| 79 | - 'post_author' => $new_lesson_author_id |
|
| 78 | + 'ID' => $quiz_item, |
|
| 79 | + 'post_author' => $new_lesson_author_id |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - // remove the action so that it doesn't fire again |
|
| 83 | - remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 82 | + // remove the action so that it doesn't fire again |
|
| 83 | + remove_action( 'save_post', array( $this, 'update_author' )); |
|
| 84 | 84 | |
| 85 | 85 | // Update the post into the database |
| 86 | 86 | wp_update_post( $my_post ); |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return; |
|
| 89 | + return; |
|
| 90 | 90 | }// end update_author |
| 91 | 91 | |
| 92 | 92 | |
@@ -117,32 +117,32 @@ discard block |
||
| 117 | 117 | } // end lesson |
| 118 | 118 | |
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * user_save_quiz_answers_listener |
|
| 122 | - * |
|
| 123 | - * This function hooks into the quiz page and accepts the answer form save post. |
|
| 124 | - * @since 1.7.3 |
|
| 125 | - * @return bool $saved; |
|
| 126 | - */ |
|
| 127 | - public function user_save_quiz_answers_listener(){ |
|
| 120 | + /** |
|
| 121 | + * user_save_quiz_answers_listener |
|
| 122 | + * |
|
| 123 | + * This function hooks into the quiz page and accepts the answer form save post. |
|
| 124 | + * @since 1.7.3 |
|
| 125 | + * @return bool $saved; |
|
| 126 | + */ |
|
| 127 | + public function user_save_quiz_answers_listener(){ |
|
| 128 | 128 | |
| 129 | - if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 130 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 131 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 132 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 133 | - return; |
|
| 134 | - } |
|
| 129 | + if( ! isset( $_POST[ 'quiz_save' ]) |
|
| 130 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 131 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 132 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce' ) > 1 ) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - global $post; |
|
| 137 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 138 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 139 | - // call the save function |
|
| 140 | - self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 136 | + global $post; |
|
| 137 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 138 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 139 | + // call the save function |
|
| 140 | + self::save_user_answers( $quiz_answers, $_FILES , $lesson_id , get_current_user_id() ); |
|
| 141 | 141 | |
| 142 | - // remove the hook as it should only fire once per click |
|
| 143 | - remove_action( 'sensei_single_quiz_content_inside_before', 'user_save_quiz_answers_listener' ); |
|
| 142 | + // remove the hook as it should only fire once per click |
|
| 143 | + remove_action( 'sensei_single_quiz_content_inside_before', 'user_save_quiz_answers_listener' ); |
|
| 144 | 144 | |
| 145 | - } // end user_save_quiz_answers_listener |
|
| 145 | + } // end user_save_quiz_answers_listener |
|
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | 148 | * Save the user answers for the given lesson's quiz |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @access public |
| 154 | 154 | * |
| 155 | 155 | * @param array $quiz_answers |
| 156 | - * @param array $files from global $_FILES |
|
| 156 | + * @param array $files from global $_FILES |
|
| 157 | 157 | * @param int $lesson_id |
| 158 | 158 | * @param int $user_id |
| 159 | 159 | * |
@@ -161,11 +161,11 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){ |
| 163 | 163 | |
| 164 | - if( ! ( $user_id > 0 ) ){ |
|
| 165 | - $user_id = get_current_user_id(); |
|
| 166 | - } |
|
| 164 | + if( ! ( $user_id > 0 ) ){ |
|
| 165 | + $user_id = get_current_user_id(); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - // make sure the parameters are valid before continuing |
|
| 168 | + // make sure the parameters are valid before continuing |
|
| 169 | 169 | if( empty( $lesson_id ) || empty( $user_id ) |
| 170 | 170 | || 'lesson' != get_post_type( $lesson_id ) |
| 171 | 171 | ||!get_userdata( $user_id ) |
@@ -176,25 +176,25 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
| 179 | - // start the lesson before saving the data in case the user has not started the lesson |
|
| 180 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 179 | + // start the lesson before saving the data in case the user has not started the lesson |
|
| 180 | + $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 181 | 181 | |
| 182 | 182 | //prepare the answers |
| 183 | 183 | $prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files ); |
| 184 | 184 | |
| 185 | 185 | // save the user data |
| 186 | - $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 186 | + $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ; |
|
| 187 | 187 | |
| 188 | 188 | // were the answers saved correctly? |
| 189 | 189 | if( intval( $answers_saved ) > 0){ |
| 190 | 190 | |
| 191 | - // save transient to make retrieval faster |
|
| 192 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 193 | - set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 191 | + // save transient to make retrieval faster |
|
| 192 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 193 | + set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS ); |
|
| 194 | 194 | |
| 195 | - // update the message showed to user |
|
| 196 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 197 | - } |
|
| 195 | + // update the message showed to user |
|
| 196 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | return $answers_saved; |
| 200 | 200 | |
@@ -202,9 +202,9 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | 204 | * Get the user answers for the given lesson's quiz. |
| 205 | - * |
|
| 206 | - * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 207 | - * retrieving data for quiz answer before sensei 1.7.4 |
|
| 205 | + * |
|
| 206 | + * This function returns the data that is stored on the lesson as meta and is not compatible with |
|
| 207 | + * retrieving data for quiz answer before sensei 1.7.4 |
|
| 208 | 208 | * |
| 209 | 209 | * |
| 210 | 210 | * @since 1.7.4 |
@@ -224,27 +224,27 @@ discard block |
||
| 224 | 224 | return false; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - // save some time and get the transient cached data |
|
| 228 | - $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 229 | - $transient_cached_answers = get_transient( $transient_key ); |
|
| 227 | + // save some time and get the transient cached data |
|
| 228 | + $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 229 | + $transient_cached_answers = get_transient( $transient_key ); |
|
| 230 | 230 | |
| 231 | - // return the transient or get the values get the values from the comment meta |
|
| 232 | - if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 231 | + // return the transient or get the values get the values from the comment meta |
|
| 232 | + if( !empty( $transient_cached_answers ) && false != $transient_cached_answers ){ |
|
| 233 | 233 | |
| 234 | - $encoded_user_answers = $transient_cached_answers; |
|
| 234 | + $encoded_user_answers = $transient_cached_answers; |
|
| 235 | 235 | |
| 236 | - }else{ |
|
| 236 | + }else{ |
|
| 237 | 237 | |
| 238 | - $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 238 | + $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id , $user_id ); |
|
| 239 | 239 | |
| 240 | - } // end if transient check |
|
| 240 | + } // end if transient check |
|
| 241 | 241 | |
| 242 | 242 | if( ! is_array( $encoded_user_answers ) ){ |
| 243 | 243 | return false; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - //set the transient with the new valid data for faster retrieval in future |
|
| 247 | - set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 246 | + //set the transient with the new valid data for faster retrieval in future |
|
| 247 | + set_transient( $transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS); |
|
| 248 | 248 | |
| 249 | 249 | // decode an unserialize all answers |
| 250 | 250 | foreach( $encoded_user_answers as $question_id => $encoded_answer ) { |
@@ -278,8 +278,8 @@ discard block |
||
| 278 | 278 | $current_quiz_id = $post->ID; |
| 279 | 279 | $lesson_id = $this->get_lesson_id( $current_quiz_id ); |
| 280 | 280 | |
| 281 | - // reset all user data |
|
| 282 | - $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 281 | + // reset all user data |
|
| 282 | + $this->reset_user_lesson_data( $lesson_id, get_current_user_id() ); |
|
| 283 | 283 | |
| 284 | 284 | //this function should only run once |
| 285 | 285 | remove_action( 'template_redirect', array( $this, 'reset_button_click_listener' ) ); |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * Complete/ submit quiz hooked function |
| 291 | 291 | * |
| 292 | 292 | * This function listens to the complete button submit action and processes the users submitted answers |
| 293 | - * not that this function submits the given users quiz answers for grading. |
|
| 293 | + * not that this function submits the given users quiz answers for grading. |
|
| 294 | 294 | * |
| 295 | 295 | * @since 1.7.4 |
| 296 | 296 | * @access public |
@@ -300,90 +300,90 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | public function user_quiz_submit_listener() { |
| 302 | 302 | |
| 303 | - // only respond to valid quiz completion submissions |
|
| 304 | - if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 305 | - || !isset( $_POST[ 'sensei_question' ] ) |
|
| 306 | - || empty( $_POST[ 'sensei_question' ] ) |
|
| 307 | - || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 308 | - return; |
|
| 309 | - } |
|
| 303 | + // only respond to valid quiz completion submissions |
|
| 304 | + if( ! isset( $_POST[ 'quiz_complete' ]) |
|
| 305 | + || !isset( $_POST[ 'sensei_question' ] ) |
|
| 306 | + || empty( $_POST[ 'sensei_question' ] ) |
|
| 307 | + || ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce' ) > 1 ) { |
|
| 308 | + return; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - global $post, $current_user; |
|
| 312 | - $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 313 | - $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 311 | + global $post, $current_user; |
|
| 312 | + $lesson_id = $this->get_lesson_id( $post->ID ); |
|
| 313 | + $quiz_answers = $_POST[ 'sensei_question' ]; |
|
| 314 | 314 | |
| 315 | - self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 315 | + self::submit_answers_for_grading( $quiz_answers, $_FILES , $lesson_id , $current_user->ID ); |
|
| 316 | 316 | |
| 317 | 317 | } // End sensei_complete_quiz() |
| 318 | 318 | |
| 319 | - /** |
|
| 320 | - * This function set's up the data need for the quiz page |
|
| 321 | - * |
|
| 322 | - * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 323 | - * current quiz. |
|
| 324 | - * |
|
| 325 | - * @since 1.7.4 |
|
| 326 | - * @access public |
|
| 327 | - * |
|
| 328 | - */ |
|
| 329 | - public function load_global_quiz_data(){ |
|
| 319 | + /** |
|
| 320 | + * This function set's up the data need for the quiz page |
|
| 321 | + * |
|
| 322 | + * This function hooks into sensei_complete_quiz and load the global data for the |
|
| 323 | + * current quiz. |
|
| 324 | + * |
|
| 325 | + * @since 1.7.4 |
|
| 326 | + * @access public |
|
| 327 | + * |
|
| 328 | + */ |
|
| 329 | + public function load_global_quiz_data(){ |
|
| 330 | 330 | |
| 331 | - global $post, $current_user; |
|
| 332 | - $this->data = new stdClass(); |
|
| 331 | + global $post, $current_user; |
|
| 332 | + $this->data = new stdClass(); |
|
| 333 | 333 | |
| 334 | - // Default grade |
|
| 335 | - $grade = 0; |
|
| 334 | + // Default grade |
|
| 335 | + $grade = 0; |
|
| 336 | 336 | |
| 337 | - // Get Quiz Questions |
|
| 338 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 337 | + // Get Quiz Questions |
|
| 338 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID ); |
|
| 339 | 339 | |
| 340 | - $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 340 | + $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) ); |
|
| 341 | 341 | |
| 342 | - // Get quiz grade type |
|
| 343 | - $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 342 | + // Get quiz grade type |
|
| 343 | + $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true ); |
|
| 344 | 344 | |
| 345 | - // Get quiz pass setting |
|
| 346 | - $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 345 | + // Get quiz pass setting |
|
| 346 | + $pass_required = get_post_meta( $post->ID, '_pass_required', true ); |
|
| 347 | 347 | |
| 348 | - // Get quiz pass mark |
|
| 349 | - $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 348 | + // Get quiz pass mark |
|
| 349 | + $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) ); |
|
| 350 | 350 | |
| 351 | - // Get latest quiz answers and grades |
|
| 352 | - $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 353 | - $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 354 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 355 | - $user_quiz_grade = 0; |
|
| 356 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 357 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 358 | - } |
|
| 351 | + // Get latest quiz answers and grades |
|
| 352 | + $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID ); |
|
| 353 | + $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() ); |
|
| 354 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID ); |
|
| 355 | + $user_quiz_grade = 0; |
|
| 356 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 357 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 360 | + if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); } |
|
| 361 | 361 | |
| 362 | - // Check again that the lesson is complete |
|
| 363 | - $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 364 | - $user_lesson_complete = false; |
|
| 365 | - if ( $user_lesson_end ) { |
|
| 366 | - $user_lesson_complete = true; |
|
| 367 | - } // End If Statement |
|
| 362 | + // Check again that the lesson is complete |
|
| 363 | + $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status ); |
|
| 364 | + $user_lesson_complete = false; |
|
| 365 | + if ( $user_lesson_end ) { |
|
| 366 | + $user_lesson_complete = true; |
|
| 367 | + } // End If Statement |
|
| 368 | 368 | |
| 369 | - $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 370 | - //backwards compatibility |
|
| 371 | - if( 'on' == $reset_allowed ) { |
|
| 372 | - $reset_allowed = 1; |
|
| 373 | - } |
|
| 369 | + $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); |
|
| 370 | + //backwards compatibility |
|
| 371 | + if( 'on' == $reset_allowed ) { |
|
| 372 | + $reset_allowed = 1; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - // Build frontend data object for backwards compatibility |
|
| 376 | - // using this is no longer recommended |
|
| 377 | - $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 378 | - $this->data->quiz_passmark = $quiz_passmark; |
|
| 379 | - $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 380 | - $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 381 | - $this->data->user_lesson_end = $user_lesson_end; |
|
| 382 | - $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 383 | - $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 384 | - $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 375 | + // Build frontend data object for backwards compatibility |
|
| 376 | + // using this is no longer recommended |
|
| 377 | + $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() ); |
|
| 378 | + $this->data->quiz_passmark = $quiz_passmark; |
|
| 379 | + $this->data->quiz_lesson = $quiz_lesson_id; |
|
| 380 | + $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 381 | + $this->data->user_lesson_end = $user_lesson_end; |
|
| 382 | + $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() ); |
|
| 383 | + $this->data->lesson_quiz_questions = $lesson_quiz_questions; |
|
| 384 | + $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id ); |
|
| 385 | 385 | |
| 386 | - } // end load_global_quiz_data |
|
| 386 | + } // end load_global_quiz_data |
|
| 387 | 387 | |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -413,25 +413,25 @@ discard block |
||
| 413 | 413 | foreach( $unprepared_answers as $question_id => $answer ) { |
| 414 | 414 | |
| 415 | 415 | //get the current questions question type |
| 416 | - $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 416 | + $question_type = Sensei()->question->get_question_type( $question_id ); |
|
| 417 | 417 | |
| 418 | 418 | // Sanitise answer |
| 419 | 419 | if( 0 == get_magic_quotes_gpc() ) { |
| 420 | 420 | $answer = wp_unslash( $answer ); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - // compress the answer for saving |
|
| 423 | + // compress the answer for saving |
|
| 424 | 424 | if( 'multi-line' == $question_type ) { |
| 425 | - $answer = esc_html( $answer ); |
|
| 426 | - }elseif( 'file-upload' == $question_type ){ |
|
| 427 | - $file_key = 'file_upload_' . $question_id; |
|
| 428 | - if( isset( $files[ $file_key ] ) ) { |
|
| 429 | - $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 430 | - if( $attachment_id ) { |
|
| 431 | - $answer = $attachment_id; |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } // end if |
|
| 425 | + $answer = esc_html( $answer ); |
|
| 426 | + }elseif( 'file-upload' == $question_type ){ |
|
| 427 | + $file_key = 'file_upload_' . $question_id; |
|
| 428 | + if( isset( $files[ $file_key ] ) ) { |
|
| 429 | + $attachment_id = Sensei_Utils::upload_file( $files[ $file_key ] ); |
|
| 430 | + if( $attachment_id ) { |
|
| 431 | + $answer = $attachment_id; |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } // end if |
|
| 435 | 435 | |
| 436 | 436 | $prepared_answers[ $question_id ] = base64_encode( maybe_serialize( $answer ) ); |
| 437 | 437 | |
@@ -440,813 +440,813 @@ discard block |
||
| 440 | 440 | return $prepared_answers; |
| 441 | 441 | } // prepare_form_submitted_answers |
| 442 | 442 | |
| 443 | - /** |
|
| 444 | - * Reset user submitted questions |
|
| 445 | - * |
|
| 446 | - * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 447 | - * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 448 | - * |
|
| 449 | - * @since 1.7.4 |
|
| 450 | - * @access public |
|
| 451 | - * |
|
| 452 | - * @return bool $reset_success |
|
| 453 | - * @param int $user_id |
|
| 454 | - * @param int $lesson_id |
|
| 455 | - */ |
|
| 456 | - public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 443 | + /** |
|
| 444 | + * Reset user submitted questions |
|
| 445 | + * |
|
| 446 | + * This function resets the quiz data for a user that has been submitted fro grading already. It is different to |
|
| 447 | + * the save_user_answers as currently the saved and submitted answers are stored differently. |
|
| 448 | + * |
|
| 449 | + * @since 1.7.4 |
|
| 450 | + * @access public |
|
| 451 | + * |
|
| 452 | + * @return bool $reset_success |
|
| 453 | + * @param int $user_id |
|
| 454 | + * @param int $lesson_id |
|
| 455 | + */ |
|
| 456 | + public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){ |
|
| 457 | + |
|
| 458 | + //make sure the parameters are valid |
|
| 459 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 460 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 461 | + || ! get_userdata( $user_id ) ){ |
|
| 462 | + return false; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + //get the users lesson status to make |
|
| 468 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 469 | + if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 470 | + // this user is not taking this lesson so this process is not needed |
|
| 471 | + return false; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + //get the lesson quiz and course |
|
| 475 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 476 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 477 | + |
|
| 478 | + // reset the transients |
|
| 479 | + $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 480 | + $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 481 | + $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 482 | + delete_transient( $answers_transient_key ); |
|
| 483 | + delete_transient( $grades_transient_key ); |
|
| 484 | + delete_transient( $answers_feedback_transient_key ); |
|
| 485 | + |
|
| 486 | + // reset the quiz answers and feedback notes |
|
| 487 | + $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 488 | + $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 489 | + $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 490 | + |
|
| 491 | + // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 492 | + Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 493 | + |
|
| 494 | + Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 495 | + |
|
| 496 | + // Update course completion |
|
| 497 | + Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 457 | 498 | |
| 458 | - //make sure the parameters are valid |
|
| 459 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 460 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 461 | - || ! get_userdata( $user_id ) ){ |
|
| 462 | - return false; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - //get the users lesson status to make |
|
| 468 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 469 | - if( ! isset( $user_lesson_status->comment_ID ) ) { |
|
| 470 | - // this user is not taking this lesson so this process is not needed |
|
| 471 | - return false; |
|
| 472 | - } |
|
| 499 | + // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 500 | + do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 501 | + Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 473 | 502 | |
| 474 | - //get the lesson quiz and course |
|
| 475 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 476 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 503 | + return ( $deleted_answers && $deleted_grades ) ; |
|
| 477 | 504 | |
| 478 | - // reset the transients |
|
| 479 | - $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id; |
|
| 480 | - $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id; |
|
| 481 | - $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 482 | - delete_transient( $answers_transient_key ); |
|
| 483 | - delete_transient( $grades_transient_key ); |
|
| 484 | - delete_transient( $answers_feedback_transient_key ); |
|
| 505 | + } // end reset_user_lesson_data |
|
| 485 | 506 | |
| 486 | - // reset the quiz answers and feedback notes |
|
| 487 | - $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id ); |
|
| 488 | - $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 489 | - $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 507 | + /** |
|
| 508 | + * Submit the users quiz answers for grading |
|
| 509 | + * |
|
| 510 | + * This function accepts users answers and stores it but also initiates the grading |
|
| 511 | + * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 512 | + * |
|
| 513 | + * @since 1.7.4 |
|
| 514 | + * @access public |
|
| 515 | + * |
|
| 516 | + * @param array $quiz_answers |
|
| 517 | + * @param array $files from $_FILES |
|
| 518 | + * @param int $user_id |
|
| 519 | + * @param int $lesson_id |
|
| 520 | + * |
|
| 521 | + * @return bool $answers_submitted |
|
| 522 | + */ |
|
| 523 | + public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 490 | 524 | |
| 491 | - // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade |
|
| 492 | - Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id ); |
|
| 525 | + $answers_submitted = false; |
|
| 493 | 526 | |
| 494 | - Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) ); |
|
| 527 | + // get the user_id if none was passed in use the current logged in user |
|
| 528 | + if( ! intval( $user_id ) > 0 ) { |
|
| 529 | + $user_id = get_current_user_id(); |
|
| 530 | + } |
|
| 495 | 531 | |
| 496 | - // Update course completion |
|
| 497 | - Sensei_Utils::update_course_status( $user_id, $course_id ); |
|
| 532 | + // make sure the parameters are valid before continuing |
|
| 533 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 534 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 535 | + ||!get_userdata( $user_id ) |
|
| 536 | + || !is_array( $quiz_answers ) ){ |
|
| 498 | 537 | |
| 499 | - // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson() |
|
| 500 | - do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id ); |
|
| 501 | - Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 538 | + return false; |
|
| 502 | 539 | |
| 503 | - return ( $deleted_answers && $deleted_grades ) ; |
|
| 540 | + } |
|
| 504 | 541 | |
| 505 | - } // end reset_user_lesson_data |
|
| 542 | + // Default grade |
|
| 543 | + $grade = 0; |
|
| 506 | 544 | |
| 507 | - /** |
|
| 508 | - * Submit the users quiz answers for grading |
|
| 509 | - * |
|
| 510 | - * This function accepts users answers and stores it but also initiates the grading |
|
| 511 | - * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. |
|
| 512 | - * |
|
| 513 | - * @since 1.7.4 |
|
| 514 | - * @access public |
|
| 515 | - * |
|
| 516 | - * @param array $quiz_answers |
|
| 517 | - * @param array $files from $_FILES |
|
| 518 | - * @param int $user_id |
|
| 519 | - * @param int $lesson_id |
|
| 520 | - * |
|
| 521 | - * @return bool $answers_submitted |
|
| 522 | - */ |
|
| 523 | - public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){ |
|
| 545 | + // Get Quiz ID |
|
| 546 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 524 | 547 | |
| 525 | - $answers_submitted = false; |
|
| 548 | + // Get quiz grade type |
|
| 549 | + $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 526 | 550 | |
| 527 | - // get the user_id if none was passed in use the current logged in user |
|
| 528 | - if( ! intval( $user_id ) > 0 ) { |
|
| 529 | - $user_id = get_current_user_id(); |
|
| 530 | - } |
|
| 551 | + // Get quiz pass setting |
|
| 552 | + $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 531 | 553 | |
| 532 | - // make sure the parameters are valid before continuing |
|
| 533 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 534 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 535 | - ||!get_userdata( $user_id ) |
|
| 536 | - || !is_array( $quiz_answers ) ){ |
|
| 554 | + // Get the minimum percentage need to pass this quiz |
|
| 555 | + $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 537 | 556 | |
| 538 | - return false; |
|
| 557 | + // Handle Quiz Questions asked |
|
| 558 | + // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 559 | + // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 560 | + // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 561 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 562 | + $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 563 | + if( empty( $questions_asked ) ){ |
|
| 539 | 564 | |
| 540 | - } |
|
| 565 | + $questions_asked = array_keys( $quiz_answers ); |
|
| 566 | + $questions_asked_string = implode( ',', $questions_asked ); |
|
| 541 | 567 | |
| 542 | - // Default grade |
|
| 543 | - $grade = 0; |
|
| 568 | + // Save questions that were asked in this quiz |
|
| 569 | + update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 544 | 570 | |
| 545 | - // Get Quiz ID |
|
| 546 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 571 | + } |
|
| 547 | 572 | |
| 548 | - // Get quiz grade type |
|
| 549 | - $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
|
| 573 | + // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 574 | + self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 550 | 575 | |
| 551 | - // Get quiz pass setting |
|
| 552 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 576 | + // Grade quiz |
|
| 577 | + $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 553 | 578 | |
| 554 | - // Get the minimum percentage need to pass this quiz |
|
| 555 | - $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) ); |
|
| 579 | + // Get Lesson Grading Setting |
|
| 580 | + $lesson_metadata = array(); |
|
| 581 | + $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 556 | 582 | |
| 557 | - // Handle Quiz Questions asked |
|
| 558 | - // This is to ensure we save the questions that we've asked this user and that this can't be change unless |
|
| 559 | - // the quiz is reset by admin or user( user: only if the setting is enabled ). |
|
| 560 | - // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions |
|
| 561 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 562 | - $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ); |
|
| 563 | - if( empty( $questions_asked ) ){ |
|
| 583 | + // At this point the answers have been submitted |
|
| 584 | + $answers_submitted = true; |
|
| 564 | 585 | |
| 565 | - $questions_asked = array_keys( $quiz_answers ); |
|
| 566 | - $questions_asked_string = implode( ',', $questions_asked ); |
|
| 567 | - |
|
| 568 | - // Save questions that were asked in this quiz |
|
| 569 | - update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string ); |
|
| 586 | + // if this condition is false the quiz should manually be graded by admin |
|
| 587 | + if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 570 | 588 | |
| 571 | - } |
|
| 589 | + // Quiz has been automatically Graded |
|
| 590 | + if ( 'on' == $pass_required ) { |
|
| 572 | 591 | |
| 573 | - // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson |
|
| 574 | - self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id ); |
|
| 592 | + // Student has reached the pass mark and lesson is complete |
|
| 593 | + if ( $quiz_pass_percentage <= $grade ) { |
|
| 575 | 594 | |
| 576 | - // Grade quiz |
|
| 577 | - $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type ); |
|
| 595 | + $lesson_status = 'passed'; |
|
| 578 | 596 | |
| 579 | - // Get Lesson Grading Setting |
|
| 580 | - $lesson_metadata = array(); |
|
| 581 | - $lesson_status = 'ungraded'; // Default when completing a quiz |
|
| 597 | + } else { |
|
| 582 | 598 | |
| 583 | - // At this point the answers have been submitted |
|
| 584 | - $answers_submitted = true; |
|
| 599 | + $lesson_status = 'failed'; |
|
| 585 | 600 | |
| 586 | - // if this condition is false the quiz should manually be graded by admin |
|
| 587 | - if ('auto' == $quiz_grade_type && ! is_wp_error( $grade ) ) { |
|
| 601 | + } // End If Statement |
|
| 588 | 602 | |
| 589 | - // Quiz has been automatically Graded |
|
| 590 | - if ( 'on' == $pass_required ) { |
|
| 603 | + } else { |
|
| 591 | 604 | |
| 592 | - // Student has reached the pass mark and lesson is complete |
|
| 593 | - if ( $quiz_pass_percentage <= $grade ) { |
|
| 605 | + // Student only has to partake the quiz |
|
| 606 | + $lesson_status = 'graded'; |
|
| 607 | + |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 611 | + |
|
| 612 | + } // end if ! is_wp_error( $grade ... |
|
| 613 | + |
|
| 614 | + Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 594 | 615 | |
| 595 | - $lesson_status = 'passed'; |
|
| 616 | + if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 596 | 617 | |
| 597 | - } else { |
|
| 618 | + /** |
|
| 619 | + * Lesson end action hook |
|
| 620 | + * |
|
| 621 | + * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 622 | + * |
|
| 623 | + * @param int $user_id |
|
| 624 | + * @param int $lesson_id |
|
| 625 | + */ |
|
| 626 | + do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 598 | 627 | |
| 599 | - $lesson_status = 'failed'; |
|
| 628 | + } |
|
| 600 | 629 | |
| 601 | - } // End If Statement |
|
| 630 | + /** |
|
| 631 | + * User quiz has been submitted |
|
| 632 | + * |
|
| 633 | + * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 634 | + * results. |
|
| 635 | + * |
|
| 636 | + * @param int $user_id |
|
| 637 | + * @param int $quiz_id |
|
| 638 | + * @param string $grade |
|
| 639 | + * @param string $quiz_pass_percentage |
|
| 640 | + * @param string $quiz_grade_type |
|
| 641 | + */ |
|
| 642 | + do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 602 | 643 | |
| 603 | - } else { |
|
| 644 | + return $answers_submitted; |
|
| 604 | 645 | |
| 605 | - // Student only has to partake the quiz |
|
| 606 | - $lesson_status = 'graded'; |
|
| 607 | - |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above |
|
| 611 | - |
|
| 612 | - } // end if ! is_wp_error( $grade ... |
|
| 613 | - |
|
| 614 | - Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata ); |
|
| 646 | + }// end submit_answers_for_grading |
|
| 615 | 647 | |
| 616 | - if( 'passed' == $lesson_status || 'graded' == $lesson_status ){ |
|
| 648 | + /** |
|
| 649 | + * Get the user question answer |
|
| 650 | + * |
|
| 651 | + * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 652 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 653 | + * |
|
| 654 | + * @since 1.7.4 |
|
| 655 | + * |
|
| 656 | + * @param int $lesson_id |
|
| 657 | + * @param int $question_id |
|
| 658 | + * @param int $user_id ( optional ) |
|
| 659 | + * |
|
| 660 | + * @return bool $answers_submitted |
|
| 661 | + */ |
|
| 662 | + public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 617 | 663 | |
| 618 | - /** |
|
| 619 | - * Lesson end action hook |
|
| 620 | - * |
|
| 621 | - * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' |
|
| 622 | - * |
|
| 623 | - * @param int $user_id |
|
| 624 | - * @param int $lesson_id |
|
| 625 | - */ |
|
| 626 | - do_action( 'sensei_user_lesson_end', $user_id, $lesson_id ); |
|
| 664 | + // parameter validation |
|
| 665 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 666 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 667 | + || ! ( intval( $question_id ) > 0 ) |
|
| 668 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 669 | + || 'question' != get_post_type( $question_id )) { |
|
| 627 | 670 | |
| 628 | - } |
|
| 671 | + return false; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 675 | + $user_id = get_current_user_id(); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 679 | + |
|
| 680 | + if( !$users_answers || empty( $users_answers ) |
|
| 681 | + || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 682 | + |
|
| 683 | + //Fallback for pre 1.7.4 data |
|
| 684 | + $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 685 | + |
|
| 686 | + if( ! isset( $comment->comment_content ) ){ |
|
| 687 | + return false; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + return $users_answers[ $question_id ]; |
|
| 694 | + |
|
| 695 | + }// end get_user_question_answer |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Saving the users quiz question grades |
|
| 699 | + * |
|
| 700 | + * This function save all the grades for all the question in a given quiz on the lesson |
|
| 701 | + * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 702 | + * |
|
| 703 | + * @since 1.7.4 |
|
| 704 | + * |
|
| 705 | + * @param array $quiz_grades{ |
|
| 706 | + * @type int $question_id |
|
| 707 | + * @type int $question_grade |
|
| 708 | + * } |
|
| 709 | + * @param $lesson_id |
|
| 710 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 711 | + * |
|
| 712 | + * @return bool |
|
| 713 | + */ |
|
| 714 | + public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 715 | + |
|
| 716 | + // get the user_id if none was passed in use the current logged in user |
|
| 717 | + if( ! intval( $user_id ) > 0 ) { |
|
| 718 | + $user_id = get_current_user_id(); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + // make sure the parameters are valid before continuing |
|
| 722 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 723 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 724 | + ||!get_userdata( $user_id ) |
|
| 725 | + || !is_array( $quiz_grades ) ){ |
|
| 726 | + |
|
| 727 | + return false; |
|
| 728 | + |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + $success = false; |
|
| 732 | + |
|
| 733 | + // save that data for the user on the lesson comment meta |
|
| 734 | + $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 735 | + |
|
| 736 | + // were the grades save successfully ? |
|
| 737 | + if( intval( $comment_meta_id ) > 0 ) { |
|
| 738 | + |
|
| 739 | + $success = true; |
|
| 740 | + // save transient |
|
| 741 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 742 | + set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + return $success; |
|
| 746 | + |
|
| 747 | + }// end set_user_grades |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * Retrieve the users quiz question grades |
|
| 751 | + * |
|
| 752 | + * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 753 | + * |
|
| 754 | + * @since 1.7.4 |
|
| 755 | + * |
|
| 756 | + * @param $lesson_id |
|
| 757 | + * @param $user_id (Optional) will use the current user if not supplied |
|
| 758 | + * |
|
| 759 | + * @return array $user_quiz_grades or false if none exists for this users |
|
| 760 | + */ |
|
| 761 | + public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 762 | + |
|
| 763 | + $user_grades = array(); |
|
| 764 | + |
|
| 765 | + // get the user_id if none was passed in use the current logged in user |
|
| 766 | + if( ! intval( $user_id ) > 0 ) { |
|
| 767 | + $user_id = get_current_user_id(); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 771 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 772 | + return false; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + // save some time and get the transient cached data |
|
| 776 | + $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 777 | + $user_grades = get_transient( $transient_key ); |
|
| 778 | + |
|
| 779 | + // get the data if nothing was stored in the transient |
|
| 780 | + if( empty( $user_grades ) || false != $user_grades ){ |
|
| 781 | + |
|
| 782 | + $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 783 | + |
|
| 784 | + //set the transient with the new valid data for faster retrieval in future |
|
| 785 | + set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 786 | + |
|
| 787 | + } // end if transient check |
|
| 788 | + |
|
| 789 | + // if there is no data for this user |
|
| 790 | + if( ! is_array( $user_grades ) ){ |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + return $user_grades; |
|
| 795 | + |
|
| 796 | + }// end get_user_grades |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * Get the user question grade |
|
| 800 | + * |
|
| 801 | + * This function gets the grade on a quiz for the given question parameter |
|
| 802 | + * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 803 | + * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 804 | + * |
|
| 805 | + * @since 1.7.4 |
|
| 806 | + * |
|
| 807 | + * @param int $lesson_id |
|
| 808 | + * @param int $question_id |
|
| 809 | + * @param int $user_id ( optional ) |
|
| 810 | + * |
|
| 811 | + * @return bool $question_grade |
|
| 812 | + */ |
|
| 813 | + public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 814 | + |
|
| 815 | + // parameter validation |
|
| 816 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 817 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 818 | + || ! ( intval( $question_id ) > 0 ) |
|
| 819 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 820 | + || 'question' != get_post_type( $question_id )) { |
|
| 821 | + |
|
| 822 | + return false; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 826 | + |
|
| 827 | + if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 828 | + |
|
| 829 | + //fallback to data pre 1.7.4 |
|
| 830 | + $args = array( |
|
| 831 | + 'post_id' => $question_id, |
|
| 832 | + 'user_id' => $user_id, |
|
| 833 | + 'type' => 'sensei_user_answer' |
|
| 834 | + ); |
|
| 835 | + |
|
| 836 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 837 | + $fall_back_grade = false; |
|
| 838 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 839 | + $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + return $fall_back_grade; |
|
| 843 | + |
|
| 844 | + } // end if $all_user_grades... |
|
| 845 | + |
|
| 846 | + return $all_user_grades[ $question_id ]; |
|
| 847 | + |
|
| 848 | + }// end get_user_question_grade |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * Save the user's answers feedback |
|
| 852 | + * |
|
| 853 | + * For this function you must supply all three parameters. If will return false one is left out. |
|
| 854 | + * The data will be saved on the lesson ID supplied. |
|
| 855 | + * |
|
| 856 | + * @since 1.7.5 |
|
| 857 | + * @access public |
|
| 858 | + * |
|
| 859 | + * @param array $answers_feedback{ |
|
| 860 | + * $type int $question_id |
|
| 861 | + * $type string $question_feedback |
|
| 862 | + * } |
|
| 863 | + * @param int $lesson_id |
|
| 864 | + * @param int $user_id |
|
| 865 | + * |
|
| 866 | + * @return false or int $feedback_saved |
|
| 867 | + */ |
|
| 868 | + public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 869 | + |
|
| 870 | + // make sure the parameters are valid before continuing |
|
| 871 | + if( empty( $lesson_id ) || empty( $user_id ) |
|
| 872 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 873 | + ||!get_userdata( $user_id ) |
|
| 874 | + || !is_array( $answers_feedback ) ){ |
|
| 875 | + |
|
| 876 | + return false; |
|
| 877 | + |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + |
|
| 881 | + // check if the lesson is started before saving, if not start the lesson for the user |
|
| 882 | + if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 883 | + Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 884 | + } |
|
| 629 | 885 | |
| 630 | - /** |
|
| 631 | - * User quiz has been submitted |
|
| 632 | - * |
|
| 633 | - * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission |
|
| 634 | - * results. |
|
| 635 | - * |
|
| 636 | - * @param int $user_id |
|
| 637 | - * @param int $quiz_id |
|
| 638 | - * @param string $grade |
|
| 639 | - * @param string $quiz_pass_percentage |
|
| 640 | - * @param string $quiz_grade_type |
|
| 641 | - */ |
|
| 642 | - do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type ); |
|
| 886 | + // encode the feedback |
|
| 887 | + $encoded_answers_feedback = array(); |
|
| 888 | + foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 889 | + $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + // save the user data |
|
| 893 | + $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 894 | + |
|
| 895 | + //Were the the question feedback save correctly? |
|
| 896 | + if( intval( $feedback_saved ) > 0){ |
|
| 897 | + |
|
| 898 | + // save transient to make retrieval faster in future |
|
| 899 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 900 | + set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 643 | 901 | |
| 644 | - return $answers_submitted; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + return $feedback_saved; |
|
| 905 | + |
|
| 906 | + } // end save_user_answers_feedback |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * Get the user's answers feedback. |
|
| 910 | + * |
|
| 911 | + * This function returns the feedback submitted by the teacher/admin |
|
| 912 | + * during grading. Grading occurs manually or automatically. |
|
| 913 | + * |
|
| 914 | + * @since 1.7.5 |
|
| 915 | + * @access public |
|
| 916 | + * |
|
| 917 | + * @param int $lesson_id |
|
| 918 | + * @param int $user_id |
|
| 919 | + * |
|
| 920 | + * @return false | array $answers_feedback{ |
|
| 921 | + * $type int $question_id |
|
| 922 | + * $type string $question_feedback |
|
| 923 | + * } |
|
| 924 | + */ |
|
| 925 | + public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 926 | + |
|
| 927 | + $answers_feedback = array(); |
|
| 645 | 928 | |
| 646 | - }// end submit_answers_for_grading |
|
| 929 | + // get the user_id if none was passed in use the current logged in user |
|
| 930 | + if( ! intval( $user_id ) > 0 ) { |
|
| 931 | + $user_id = get_current_user_id(); |
|
| 932 | + } |
|
| 647 | 933 | |
| 648 | - /** |
|
| 649 | - * Get the user question answer |
|
| 650 | - * |
|
| 651 | - * This function gets the the users saved answer on given quiz for the given question parameter |
|
| 652 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 653 | - * |
|
| 654 | - * @since 1.7.4 |
|
| 655 | - * |
|
| 656 | - * @param int $lesson_id |
|
| 657 | - * @param int $question_id |
|
| 658 | - * @param int $user_id ( optional ) |
|
| 659 | - * |
|
| 660 | - * @return bool $answers_submitted |
|
| 661 | - */ |
|
| 662 | - public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 934 | + if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 935 | + || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 936 | + return false; |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + // first check the transient to save a few split seconds |
|
| 940 | + $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 941 | + $encoded_feedback = get_transient( $transient_key ); |
|
| 942 | + |
|
| 943 | + // get the data if nothing was stored in the transient |
|
| 944 | + if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 945 | + |
|
| 946 | + $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 947 | + |
|
| 948 | + //set the transient with the new valid data for faster retrieval in future |
|
| 949 | + set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 950 | + |
|
| 951 | + } // end if transient check |
|
| 663 | 952 | |
| 664 | - // parameter validation |
|
| 665 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 666 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 667 | - || ! ( intval( $question_id ) > 0 ) |
|
| 668 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 669 | - || 'question' != get_post_type( $question_id )) { |
|
| 953 | + // if there is no data for this user |
|
| 954 | + if( ! is_array( $encoded_feedback ) ){ |
|
| 955 | + return false; |
|
| 956 | + } |
|
| 670 | 957 | |
| 671 | - return false; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - if( ! ( intval( $user_id ) > 0 ) ){ |
|
| 675 | - $user_id = get_current_user_id(); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - $users_answers = $this->get_user_answers( $lesson_id, $user_id ); |
|
| 679 | - |
|
| 680 | - if( !$users_answers || empty( $users_answers ) |
|
| 681 | - || ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){ |
|
| 682 | - |
|
| 683 | - //Fallback for pre 1.7.4 data |
|
| 684 | - $comment = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true ); |
|
| 685 | - |
|
| 686 | - if( ! isset( $comment->comment_content ) ){ |
|
| 687 | - return false; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - return maybe_unserialize( base64_decode( $comment->comment_content ) ); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - return $users_answers[ $question_id ]; |
|
| 694 | - |
|
| 695 | - }// end get_user_question_answer |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Saving the users quiz question grades |
|
| 699 | - * |
|
| 700 | - * This function save all the grades for all the question in a given quiz on the lesson |
|
| 701 | - * comment meta. It makes use of transients to save the grades for easier access at a later stage |
|
| 702 | - * |
|
| 703 | - * @since 1.7.4 |
|
| 704 | - * |
|
| 705 | - * @param array $quiz_grades{ |
|
| 706 | - * @type int $question_id |
|
| 707 | - * @type int $question_grade |
|
| 708 | - * } |
|
| 709 | - * @param $lesson_id |
|
| 710 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 711 | - * |
|
| 712 | - * @return bool |
|
| 713 | - */ |
|
| 714 | - public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){ |
|
| 715 | - |
|
| 716 | - // get the user_id if none was passed in use the current logged in user |
|
| 717 | - if( ! intval( $user_id ) > 0 ) { |
|
| 718 | - $user_id = get_current_user_id(); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - // make sure the parameters are valid before continuing |
|
| 722 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 723 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 724 | - ||!get_userdata( $user_id ) |
|
| 725 | - || !is_array( $quiz_grades ) ){ |
|
| 726 | - |
|
| 727 | - return false; |
|
| 728 | - |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - $success = false; |
|
| 732 | - |
|
| 733 | - // save that data for the user on the lesson comment meta |
|
| 734 | - $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id ); |
|
| 735 | - |
|
| 736 | - // were the grades save successfully ? |
|
| 737 | - if( intval( $comment_meta_id ) > 0 ) { |
|
| 738 | - |
|
| 739 | - $success = true; |
|
| 740 | - // save transient |
|
| 741 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 742 | - set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS ); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - return $success; |
|
| 746 | - |
|
| 747 | - }// end set_user_grades |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * Retrieve the users quiz question grades |
|
| 751 | - * |
|
| 752 | - * This function gets all the grades for all the questions in the given lesson quiz for a specific user. |
|
| 753 | - * |
|
| 754 | - * @since 1.7.4 |
|
| 755 | - * |
|
| 756 | - * @param $lesson_id |
|
| 757 | - * @param $user_id (Optional) will use the current user if not supplied |
|
| 758 | - * |
|
| 759 | - * @return array $user_quiz_grades or false if none exists for this users |
|
| 760 | - */ |
|
| 761 | - public function get_user_grades( $lesson_id, $user_id = 0 ){ |
|
| 762 | - |
|
| 763 | - $user_grades = array(); |
|
| 764 | - |
|
| 765 | - // get the user_id if none was passed in use the current logged in user |
|
| 766 | - if( ! intval( $user_id ) > 0 ) { |
|
| 767 | - $user_id = get_current_user_id(); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 771 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 772 | - return false; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - // save some time and get the transient cached data |
|
| 776 | - $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id; |
|
| 777 | - $user_grades = get_transient( $transient_key ); |
|
| 778 | - |
|
| 779 | - // get the data if nothing was stored in the transient |
|
| 780 | - if( empty( $user_grades ) || false != $user_grades ){ |
|
| 781 | - |
|
| 782 | - $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id ); |
|
| 783 | - |
|
| 784 | - //set the transient with the new valid data for faster retrieval in future |
|
| 785 | - set_transient( $transient_key, $user_grades, 10 * DAY_IN_SECONDS ); |
|
| 786 | - |
|
| 787 | - } // end if transient check |
|
| 788 | - |
|
| 789 | - // if there is no data for this user |
|
| 790 | - if( ! is_array( $user_grades ) ){ |
|
| 791 | - return false; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - return $user_grades; |
|
| 795 | - |
|
| 796 | - }// end get_user_grades |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * Get the user question grade |
|
| 800 | - * |
|
| 801 | - * This function gets the grade on a quiz for the given question parameter |
|
| 802 | - * It does NOT do any grading. It simply retrieves the data that was stored during grading. |
|
| 803 | - * this function allows for a fallback to users still using the question saved data from before 1.7.4 |
|
| 804 | - * |
|
| 805 | - * @since 1.7.4 |
|
| 806 | - * |
|
| 807 | - * @param int $lesson_id |
|
| 808 | - * @param int $question_id |
|
| 809 | - * @param int $user_id ( optional ) |
|
| 810 | - * |
|
| 811 | - * @return bool $question_grade |
|
| 812 | - */ |
|
| 813 | - public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 814 | - |
|
| 815 | - // parameter validation |
|
| 816 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 817 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 818 | - || ! ( intval( $question_id ) > 0 ) |
|
| 819 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 820 | - || 'question' != get_post_type( $question_id )) { |
|
| 821 | - |
|
| 822 | - return false; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - $all_user_grades = self::get_user_grades( $lesson_id,$user_id ); |
|
| 826 | - |
|
| 827 | - if( ! $all_user_grades || ! isset( $all_user_grades[ $question_id ] ) ){ |
|
| 828 | - |
|
| 829 | - //fallback to data pre 1.7.4 |
|
| 830 | - $args = array( |
|
| 831 | - 'post_id' => $question_id, |
|
| 832 | - 'user_id' => $user_id, |
|
| 833 | - 'type' => 'sensei_user_answer' |
|
| 834 | - ); |
|
| 835 | - |
|
| 836 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 837 | - $fall_back_grade = false; |
|
| 838 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 839 | - $fall_back_grade = get_comment_meta( $question_activity->comment_ID , 'user_grade', true ); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - return $fall_back_grade; |
|
| 843 | - |
|
| 844 | - } // end if $all_user_grades... |
|
| 845 | - |
|
| 846 | - return $all_user_grades[ $question_id ]; |
|
| 847 | - |
|
| 848 | - }// end get_user_question_grade |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * Save the user's answers feedback |
|
| 852 | - * |
|
| 853 | - * For this function you must supply all three parameters. If will return false one is left out. |
|
| 854 | - * The data will be saved on the lesson ID supplied. |
|
| 855 | - * |
|
| 856 | - * @since 1.7.5 |
|
| 857 | - * @access public |
|
| 858 | - * |
|
| 859 | - * @param array $answers_feedback{ |
|
| 860 | - * $type int $question_id |
|
| 861 | - * $type string $question_feedback |
|
| 862 | - * } |
|
| 863 | - * @param int $lesson_id |
|
| 864 | - * @param int $user_id |
|
| 865 | - * |
|
| 866 | - * @return false or int $feedback_saved |
|
| 867 | - */ |
|
| 868 | - public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){ |
|
| 869 | - |
|
| 870 | - // make sure the parameters are valid before continuing |
|
| 871 | - if( empty( $lesson_id ) || empty( $user_id ) |
|
| 872 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 873 | - ||!get_userdata( $user_id ) |
|
| 874 | - || !is_array( $answers_feedback ) ){ |
|
| 875 | - |
|
| 876 | - return false; |
|
| 877 | - |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - |
|
| 881 | - // check if the lesson is started before saving, if not start the lesson for the user |
|
| 882 | - if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) { |
|
| 883 | - Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id ); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - // encode the feedback |
|
| 887 | - $encoded_answers_feedback = array(); |
|
| 888 | - foreach( $answers_feedback as $question_id => $feedback ){ |
|
| 889 | - $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback ); |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - // save the user data |
|
| 893 | - $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ; |
|
| 894 | - |
|
| 895 | - //Were the the question feedback save correctly? |
|
| 896 | - if( intval( $feedback_saved ) > 0){ |
|
| 897 | - |
|
| 898 | - // save transient to make retrieval faster in future |
|
| 899 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 900 | - set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS ); |
|
| 901 | - |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - return $feedback_saved; |
|
| 905 | - |
|
| 906 | - } // end save_user_answers_feedback |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * Get the user's answers feedback. |
|
| 910 | - * |
|
| 911 | - * This function returns the feedback submitted by the teacher/admin |
|
| 912 | - * during grading. Grading occurs manually or automatically. |
|
| 913 | - * |
|
| 914 | - * @since 1.7.5 |
|
| 915 | - * @access public |
|
| 916 | - * |
|
| 917 | - * @param int $lesson_id |
|
| 918 | - * @param int $user_id |
|
| 919 | - * |
|
| 920 | - * @return false | array $answers_feedback{ |
|
| 921 | - * $type int $question_id |
|
| 922 | - * $type string $question_feedback |
|
| 923 | - * } |
|
| 924 | - */ |
|
| 925 | - public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){ |
|
| 926 | - |
|
| 927 | - $answers_feedback = array(); |
|
| 928 | - |
|
| 929 | - // get the user_id if none was passed in use the current logged in user |
|
| 930 | - if( ! intval( $user_id ) > 0 ) { |
|
| 931 | - $user_id = get_current_user_id(); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id ) |
|
| 935 | - || ! intval( $user_id ) > 0 || !get_userdata( $user_id ) ) { |
|
| 936 | - return false; |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - // first check the transient to save a few split seconds |
|
| 940 | - $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id; |
|
| 941 | - $encoded_feedback = get_transient( $transient_key ); |
|
| 942 | - |
|
| 943 | - // get the data if nothing was stored in the transient |
|
| 944 | - if( empty( $encoded_feedback ) || !$encoded_feedback ){ |
|
| 945 | - |
|
| 946 | - $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id ); |
|
| 947 | - |
|
| 948 | - //set the transient with the new valid data for faster retrieval in future |
|
| 949 | - set_transient( $transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS); |
|
| 950 | - |
|
| 951 | - } // end if transient check |
|
| 952 | - |
|
| 953 | - // if there is no data for this user |
|
| 954 | - if( ! is_array( $encoded_feedback ) ){ |
|
| 955 | - return false; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 958 | + foreach( $encoded_feedback as $question_id => $feedback ){ |
|
| 959 | 959 | |
| 960 | - $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 960 | + $answers_feedback[ $question_id ] = base64_decode( $feedback ); |
|
| 961 | 961 | |
| 962 | - } |
|
| 962 | + } |
|
| 963 | 963 | |
| 964 | - return $answers_feedback; |
|
| 964 | + return $answers_feedback; |
|
| 965 | 965 | |
| 966 | - } // end get_user_answers_feedback |
|
| 966 | + } // end get_user_answers_feedback |
|
| 967 | 967 | |
| 968 | - /** |
|
| 969 | - * Get the user's answer feedback for a specific question. |
|
| 970 | - * |
|
| 971 | - * This function gives you a single answer note/feedback string |
|
| 972 | - * for the user on the given question. |
|
| 973 | - * |
|
| 974 | - * @since 1.7.5 |
|
| 975 | - * @access public |
|
| 976 | - * |
|
| 977 | - * @param int $lesson_id |
|
| 978 | - * @param int $question_id |
|
| 979 | - * @param int $user_id |
|
| 980 | - * |
|
| 981 | - * @return string $feedback or bool if false |
|
| 982 | - */ |
|
| 983 | - public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 968 | + /** |
|
| 969 | + * Get the user's answer feedback for a specific question. |
|
| 970 | + * |
|
| 971 | + * This function gives you a single answer note/feedback string |
|
| 972 | + * for the user on the given question. |
|
| 973 | + * |
|
| 974 | + * @since 1.7.5 |
|
| 975 | + * @access public |
|
| 976 | + * |
|
| 977 | + * @param int $lesson_id |
|
| 978 | + * @param int $question_id |
|
| 979 | + * @param int $user_id |
|
| 980 | + * |
|
| 981 | + * @return string $feedback or bool if false |
|
| 982 | + */ |
|
| 983 | + public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){ |
|
| 984 | 984 | |
| 985 | - $feedback = false; |
|
| 985 | + $feedback = false; |
|
| 986 | 986 | |
| 987 | - // parameter validation |
|
| 988 | - if( empty( $lesson_id ) || empty( $question_id ) |
|
| 989 | - || ! ( intval( $lesson_id ) > 0 ) |
|
| 990 | - || ! ( intval( $question_id ) > 0 ) |
|
| 991 | - || 'lesson' != get_post_type( $lesson_id ) |
|
| 992 | - || 'question' != get_post_type( $question_id )) { |
|
| 987 | + // parameter validation |
|
| 988 | + if( empty( $lesson_id ) || empty( $question_id ) |
|
| 989 | + || ! ( intval( $lesson_id ) > 0 ) |
|
| 990 | + || ! ( intval( $question_id ) > 0 ) |
|
| 991 | + || 'lesson' != get_post_type( $lesson_id ) |
|
| 992 | + || 'question' != get_post_type( $question_id )) { |
|
| 993 | 993 | |
| 994 | - return false; |
|
| 995 | - } |
|
| 994 | + return false; |
|
| 995 | + } |
|
| 996 | 996 | |
| 997 | - // get all the feedback for the user on the given lesson |
|
| 998 | - $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 997 | + // get all the feedback for the user on the given lesson |
|
| 998 | + $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id ); |
|
| 999 | 999 | |
| 1000 | - if( !$all_feedback || empty( $all_feedback ) |
|
| 1001 | - || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1000 | + if( !$all_feedback || empty( $all_feedback ) |
|
| 1001 | + || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){ |
|
| 1002 | 1002 | |
| 1003 | - //fallback to data pre 1.7.4 |
|
| 1003 | + //fallback to data pre 1.7.4 |
|
| 1004 | 1004 | |
| 1005 | - // setup the sensei data query |
|
| 1006 | - $args = array( |
|
| 1007 | - 'post_id' => $question_id, |
|
| 1008 | - 'user_id' => $user_id, |
|
| 1009 | - 'type' => 'sensei_user_answer' |
|
| 1010 | - ); |
|
| 1011 | - $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1005 | + // setup the sensei data query |
|
| 1006 | + $args = array( |
|
| 1007 | + 'post_id' => $question_id, |
|
| 1008 | + 'user_id' => $user_id, |
|
| 1009 | + 'type' => 'sensei_user_answer' |
|
| 1010 | + ); |
|
| 1011 | + $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true ); |
|
| 1012 | 1012 | |
| 1013 | - // set the default to false and return that if no old data is available. |
|
| 1014 | - if( isset( $question_activity->comment_ID ) ){ |
|
| 1015 | - $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1016 | - } |
|
| 1013 | + // set the default to false and return that if no old data is available. |
|
| 1014 | + if( isset( $question_activity->comment_ID ) ){ |
|
| 1015 | + $feedback = base64_decode( get_comment_meta( $question_activity->comment_ID , 'answer_note', true ) ); |
|
| 1016 | + } |
|
| 1017 | 1017 | |
| 1018 | - // finally use the default question feedback |
|
| 1019 | - if( empty( $feedback ) ){ |
|
| 1020 | - $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1021 | - } |
|
| 1018 | + // finally use the default question feedback |
|
| 1019 | + if( empty( $feedback ) ){ |
|
| 1020 | + $feedback = get_post_meta( $question_id, '_answer_feedback', true ); |
|
| 1021 | + } |
|
| 1022 | 1022 | |
| 1023 | - return $feedback; |
|
| 1023 | + return $feedback; |
|
| 1024 | 1024 | |
| 1025 | - } |
|
| 1025 | + } |
|
| 1026 | 1026 | |
| 1027 | - return $all_feedback[ $question_id ]; |
|
| 1027 | + return $all_feedback[ $question_id ]; |
|
| 1028 | 1028 | |
| 1029 | - } // end get_user_question_feedback |
|
| 1029 | + } // end get_user_question_feedback |
|
| 1030 | 1030 | |
| 1031 | - /** |
|
| 1032 | - * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1033 | - * |
|
| 1034 | - * Though a quiz is created for each lesson, it should not be visible |
|
| 1035 | - * unless it has questions. |
|
| 1036 | - * |
|
| 1037 | - * @since 1.9.0 |
|
| 1038 | - * @access public |
|
| 1039 | - * @param none |
|
| 1040 | - * @return void |
|
| 1041 | - */ |
|
| 1031 | + /** |
|
| 1032 | + * Check if a quiz has no questions, and redirect back to lesson. |
|
| 1033 | + * |
|
| 1034 | + * Though a quiz is created for each lesson, it should not be visible |
|
| 1035 | + * unless it has questions. |
|
| 1036 | + * |
|
| 1037 | + * @since 1.9.0 |
|
| 1038 | + * @access public |
|
| 1039 | + * @param none |
|
| 1040 | + * @return void |
|
| 1041 | + */ |
|
| 1042 | 1042 | |
| 1043 | - public function quiz_has_no_questions() { |
|
| 1043 | + public function quiz_has_no_questions() { |
|
| 1044 | 1044 | |
| 1045 | - if( ! is_singular( 'quiz' ) ) { |
|
| 1046 | - return; |
|
| 1047 | - } |
|
| 1045 | + if( ! is_singular( 'quiz' ) ) { |
|
| 1046 | + return; |
|
| 1047 | + } |
|
| 1048 | 1048 | |
| 1049 | - global $post; |
|
| 1049 | + global $post; |
|
| 1050 | 1050 | |
| 1051 | - $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1051 | + $lesson_id = $this->get_lesson_id($post->ID); |
|
| 1052 | 1052 | |
| 1053 | - $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1053 | + $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true ); |
|
| 1054 | 1054 | |
| 1055 | - $lesson = get_post($lesson_id); |
|
| 1055 | + $lesson = get_post($lesson_id); |
|
| 1056 | 1056 | |
| 1057 | - if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1057 | + if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) { |
|
| 1058 | 1058 | |
| 1059 | - wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1060 | - exit; |
|
| 1059 | + wp_redirect(get_permalink($lesson->ID), 301); |
|
| 1060 | + exit; |
|
| 1061 | 1061 | |
| 1062 | - } |
|
| 1062 | + } |
|
| 1063 | 1063 | |
| 1064 | - } // end quiz_has_no_questions |
|
| 1064 | + } // end quiz_has_no_questions |
|
| 1065 | 1065 | |
| 1066 | 1066 | /** |
| 1067 | - * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1068 | - * |
|
| 1069 | - * @deprecated since 1.9.0 |
|
| 1070 | - */ |
|
| 1067 | + * Deprecate the sensei_single_main_content on the single-quiz template. |
|
| 1068 | + * |
|
| 1069 | + * @deprecated since 1.9.0 |
|
| 1070 | + */ |
|
| 1071 | 1071 | public static function deprecate_quiz_sensei_single_main_content_hook(){ |
| 1072 | 1072 | |
| 1073 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1073 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after'); |
|
| 1074 | 1074 | |
| 1075 | 1075 | } |
| 1076 | - /* |
|
| 1076 | + /* |
|
| 1077 | 1077 | * Deprecate the sensei_quiz_single_title on the single-quiz template. |
| 1078 | 1078 | * |
| 1079 | 1079 | * @deprecated since 1.9.0 |
| 1080 | 1080 | */ |
| 1081 | - public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1081 | + public static function deprecate_quiz_sensei_quiz_single_title_hook(){ |
|
| 1082 | 1082 | |
| 1083 | - sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1083 | + sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before '); |
|
| 1084 | 1084 | |
| 1085 | - } |
|
| 1085 | + } |
|
| 1086 | 1086 | |
| 1087 | - /** |
|
| 1088 | - * Filter the single title and add the Quiz to it. |
|
| 1089 | - * |
|
| 1090 | - * @param string $title |
|
| 1091 | - * @param int $id title post id |
|
| 1092 | - * @return string $quiz_title |
|
| 1093 | - */ |
|
| 1094 | - public static function single_quiz_title( $title, $post_id ){ |
|
| 1087 | + /** |
|
| 1088 | + * Filter the single title and add the Quiz to it. |
|
| 1089 | + * |
|
| 1090 | + * @param string $title |
|
| 1091 | + * @param int $id title post id |
|
| 1092 | + * @return string $quiz_title |
|
| 1093 | + */ |
|
| 1094 | + public static function single_quiz_title( $title, $post_id ){ |
|
| 1095 | 1095 | |
| 1096 | - if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1096 | + if( 'quiz' == get_post_type( $post_id ) ){ |
|
| 1097 | 1097 | |
| 1098 | - $title_with_no_quizzes = $title; |
|
| 1098 | + $title_with_no_quizzes = $title; |
|
| 1099 | 1099 | |
| 1100 | - // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1101 | - if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1100 | + // if the title has quiz, remove it: legacy titles have the word quiz stored. |
|
| 1101 | + if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){ |
|
| 1102 | 1102 | |
| 1103 | - // remove all possible appearances of quiz |
|
| 1104 | - $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1105 | - $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1106 | - $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1103 | + // remove all possible appearances of quiz |
|
| 1104 | + $title_with_no_quizzes = str_replace( 'quiz', '', $title ); |
|
| 1105 | + $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes ); |
|
| 1106 | + $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes ); |
|
| 1107 | 1107 | |
| 1108 | - } |
|
| 1108 | + } |
|
| 1109 | 1109 | |
| 1110 | - $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1111 | - } |
|
| 1110 | + $title = $title_with_no_quizzes . ' ' . __( 'Quiz', 'woothemes-sensei' ); |
|
| 1111 | + } |
|
| 1112 | 1112 | |
| 1113 | - /** |
|
| 1114 | - * hook document in class-woothemes-sensei-message.php |
|
| 1115 | - */ |
|
| 1116 | - return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1113 | + /** |
|
| 1114 | + * hook document in class-woothemes-sensei-message.php |
|
| 1115 | + */ |
|
| 1116 | + return apply_filters( 'sensei_single_title', $title, get_post_type( ) ); |
|
| 1117 | 1117 | |
| 1118 | - } |
|
| 1118 | + } |
|
| 1119 | 1119 | |
| 1120 | - /** |
|
| 1121 | - * Initialize the quiz question loop on the single quiz template |
|
| 1122 | - * |
|
| 1123 | - * The function will create a global quiz loop varialbe. |
|
| 1124 | - * |
|
| 1125 | - * @since 1.9.0 |
|
| 1126 | - * |
|
| 1127 | - */ |
|
| 1128 | - public static function start_quiz_questions_loop(){ |
|
| 1120 | + /** |
|
| 1121 | + * Initialize the quiz question loop on the single quiz template |
|
| 1122 | + * |
|
| 1123 | + * The function will create a global quiz loop varialbe. |
|
| 1124 | + * |
|
| 1125 | + * @since 1.9.0 |
|
| 1126 | + * |
|
| 1127 | + */ |
|
| 1128 | + public static function start_quiz_questions_loop(){ |
|
| 1129 | 1129 | |
| 1130 | - global $sensei_question_loop; |
|
| 1130 | + global $sensei_question_loop; |
|
| 1131 | 1131 | |
| 1132 | - //intialize the questions loop object |
|
| 1133 | - $sensei_question_loop['current'] = -1; |
|
| 1134 | - $sensei_question_loop['total'] = 0; |
|
| 1135 | - $sensei_question_loop['questions'] = array(); |
|
| 1132 | + //intialize the questions loop object |
|
| 1133 | + $sensei_question_loop['current'] = -1; |
|
| 1134 | + $sensei_question_loop['total'] = 0; |
|
| 1135 | + $sensei_question_loop['questions'] = array(); |
|
| 1136 | 1136 | |
| 1137 | 1137 | |
| 1138 | - $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1138 | + $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() ); |
|
| 1139 | 1139 | |
| 1140 | - if( count( $questions ) > 0 ){ |
|
| 1140 | + if( count( $questions ) > 0 ){ |
|
| 1141 | 1141 | |
| 1142 | - $sensei_question_loop['total'] = count( $questions ); |
|
| 1143 | - $sensei_question_loop['questions'] = $questions; |
|
| 1144 | - $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1142 | + $sensei_question_loop['total'] = count( $questions ); |
|
| 1143 | + $sensei_question_loop['questions'] = $questions; |
|
| 1144 | + $sensei_question_loop['quiz_id'] = get_the_ID(); |
|
| 1145 | 1145 | |
| 1146 | - } |
|
| 1146 | + } |
|
| 1147 | 1147 | |
| 1148 | - }// static function |
|
| 1148 | + }// static function |
|
| 1149 | 1149 | |
| 1150 | - /** |
|
| 1151 | - * Initialize the quiz question loop on the single quiz template |
|
| 1152 | - * |
|
| 1153 | - * The function will create a global quiz loop varialbe. |
|
| 1154 | - * |
|
| 1155 | - * @since 1.9.0 |
|
| 1156 | - * |
|
| 1157 | - */ |
|
| 1158 | - public static function stop_quiz_questions_loop(){ |
|
| 1150 | + /** |
|
| 1151 | + * Initialize the quiz question loop on the single quiz template |
|
| 1152 | + * |
|
| 1153 | + * The function will create a global quiz loop varialbe. |
|
| 1154 | + * |
|
| 1155 | + * @since 1.9.0 |
|
| 1156 | + * |
|
| 1157 | + */ |
|
| 1158 | + public static function stop_quiz_questions_loop(){ |
|
| 1159 | 1159 | |
| 1160 | - $sensei_question_loop['total'] = 0; |
|
| 1161 | - $sensei_question_loop['questions'] = array(); |
|
| 1162 | - $sensei_question_loop['quiz_id'] = ''; |
|
| 1160 | + $sensei_question_loop['total'] = 0; |
|
| 1161 | + $sensei_question_loop['questions'] = array(); |
|
| 1162 | + $sensei_question_loop['quiz_id'] = ''; |
|
| 1163 | 1163 | |
| 1164 | - } |
|
| 1164 | + } |
|
| 1165 | 1165 | |
| 1166 | - /** |
|
| 1167 | - * Output the title for the single quiz page |
|
| 1168 | - * |
|
| 1169 | - * @since 1.9.0 |
|
| 1170 | - */ |
|
| 1171 | - public static function the_title(){ |
|
| 1172 | - ?> |
|
| 1166 | + /** |
|
| 1167 | + * Output the title for the single quiz page |
|
| 1168 | + * |
|
| 1169 | + * @since 1.9.0 |
|
| 1170 | + */ |
|
| 1171 | + public static function the_title(){ |
|
| 1172 | + ?> |
|
| 1173 | 1173 | <header> |
| 1174 | 1174 | |
| 1175 | 1175 | <h1> |
| 1176 | 1176 | |
| 1177 | 1177 | <?php |
| 1178 | - /** |
|
| 1179 | - * Filter documented in class-sensei-messages.php the_title |
|
| 1180 | - */ |
|
| 1181 | - echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1182 | - ?> |
|
| 1178 | + /** |
|
| 1179 | + * Filter documented in class-sensei-messages.php the_title |
|
| 1180 | + */ |
|
| 1181 | + echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) ); |
|
| 1182 | + ?> |
|
| 1183 | 1183 | |
| 1184 | 1184 | </h1> |
| 1185 | 1185 | |
| 1186 | 1186 | </header> |
| 1187 | 1187 | |
| 1188 | 1188 | <?php |
| 1189 | - }//the_title |
|
| 1189 | + }//the_title |
|
| 1190 | 1190 | |
| 1191 | - /** |
|
| 1192 | - * Output the sensei quiz status message. |
|
| 1193 | - * |
|
| 1194 | - * @param $quiz_id |
|
| 1195 | - */ |
|
| 1196 | - public static function the_user_status_message( $quiz_id ){ |
|
| 1191 | + /** |
|
| 1192 | + * Output the sensei quiz status message. |
|
| 1193 | + * |
|
| 1194 | + * @param $quiz_id |
|
| 1195 | + */ |
|
| 1196 | + public static function the_user_status_message( $quiz_id ){ |
|
| 1197 | 1197 | |
| 1198 | - $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1199 | - $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1200 | - echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1198 | + $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); |
|
| 1199 | + $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() ); |
|
| 1200 | + echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>'; |
|
| 1201 | 1201 | |
| 1202 | - } |
|
| 1202 | + } |
|
| 1203 | 1203 | |
| 1204 | - /** |
|
| 1205 | - * This functions runs the old sensei_quiz_action_buttons action |
|
| 1206 | - * for backwards compatiblity sake. |
|
| 1207 | - * |
|
| 1208 | - * @since 1.9.0 |
|
| 1209 | - * @deprecated |
|
| 1210 | - */ |
|
| 1211 | - public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1204 | + /** |
|
| 1205 | + * This functions runs the old sensei_quiz_action_buttons action |
|
| 1206 | + * for backwards compatiblity sake. |
|
| 1207 | + * |
|
| 1208 | + * @since 1.9.0 |
|
| 1209 | + * @deprecated |
|
| 1210 | + */ |
|
| 1211 | + public static function deprecate_sensei_quiz_action_buttons_hook(){ |
|
| 1212 | 1212 | |
| 1213 | - sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1213 | + sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after'); |
|
| 1214 | 1214 | |
| 1215 | - } |
|
| 1215 | + } |
|
| 1216 | 1216 | |
| 1217 | - /** |
|
| 1218 | - * The quiz action buttons needed to ouput quiz |
|
| 1219 | - * action such as reset complete and save. |
|
| 1220 | - * |
|
| 1221 | - * @since 1.3.0 |
|
| 1222 | - */ |
|
| 1223 | - public static function action_buttons() { |
|
| 1217 | + /** |
|
| 1218 | + * The quiz action buttons needed to ouput quiz |
|
| 1219 | + * action such as reset complete and save. |
|
| 1220 | + * |
|
| 1221 | + * @since 1.3.0 |
|
| 1222 | + */ |
|
| 1223 | + public static function action_buttons() { |
|
| 1224 | 1224 | |
| 1225 | - global $post, $current_user; |
|
| 1225 | + global $post, $current_user; |
|
| 1226 | 1226 | |
| 1227 | - $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1228 | - $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1229 | - $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1230 | - $show_actions = true; |
|
| 1231 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1227 | + $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true ); |
|
| 1228 | + $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true ); |
|
| 1229 | + $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true ); |
|
| 1230 | + $show_actions = true; |
|
| 1231 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID ); |
|
| 1232 | 1232 | |
| 1233 | - //setup quiz grade |
|
| 1234 | - $user_quiz_grade = ''; |
|
| 1235 | - if( ! empty( $user_lesson_status ) ){ |
|
| 1236 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1237 | - } |
|
| 1233 | + //setup quiz grade |
|
| 1234 | + $user_quiz_grade = ''; |
|
| 1235 | + if( ! empty( $user_lesson_status ) ){ |
|
| 1236 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1237 | + } |
|
| 1238 | 1238 | |
| 1239 | 1239 | |
| 1240 | - if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1240 | + if( intval( $lesson_prerequisite ) > 0 ) { |
|
| 1241 | 1241 | |
| 1242 | - // If the user hasn't completed the prereq then hide the current actions |
|
| 1243 | - $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1242 | + // If the user hasn't completed the prereq then hide the current actions |
|
| 1243 | + $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID ); |
|
| 1244 | 1244 | |
| 1245 | - } |
|
| 1246 | - if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1245 | + } |
|
| 1246 | + if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 1247 | 1247 | |
| 1248 | - // Get Reset Settings |
|
| 1249 | - $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1248 | + // Get Reset Settings |
|
| 1249 | + $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?> |
|
| 1250 | 1250 | |
| 1251 | 1251 | <!-- Action Nonce's --> |
| 1252 | 1252 | <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce" |
@@ -1273,55 +1273,55 @@ discard block |
||
| 1273 | 1273 | |
| 1274 | 1274 | <?php } |
| 1275 | 1275 | |
| 1276 | - } // End sensei_quiz_action_buttons() |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * Fetch the quiz grade |
|
| 1280 | - * |
|
| 1281 | - * @since 1.9.0 |
|
| 1282 | - * |
|
| 1283 | - * @param int $lesson_id |
|
| 1284 | - * @param int $user_id |
|
| 1285 | - * |
|
| 1286 | - * @return double $user_quiz_grade |
|
| 1287 | - */ |
|
| 1288 | - public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1289 | - |
|
| 1290 | - // get the quiz grade |
|
| 1291 | - $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1292 | - $user_quiz_grade = 0; |
|
| 1293 | - if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1294 | - $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - return (double) $user_quiz_grade; |
|
| 1298 | - |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - /** |
|
| 1302 | - * Check the quiz reset property for a given lesson's quiz. |
|
| 1303 | - * |
|
| 1304 | - * The data is stored on the quiz but going forward the quiz post |
|
| 1305 | - * type will be retired, hence the lesson_id is a require parameter. |
|
| 1306 | - * |
|
| 1307 | - * @since 1.9.0 |
|
| 1308 | - * |
|
| 1309 | - * @param int $lesson_id |
|
| 1310 | - * @return bool |
|
| 1311 | - */ |
|
| 1312 | - public static function is_reset_allowed( $lesson_id ){ |
|
| 1313 | - |
|
| 1314 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1315 | - |
|
| 1316 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1317 | - //backwards compatibility |
|
| 1318 | - if( 'on' == $reset_allowed ) { |
|
| 1319 | - $reset_allowed = 1; |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - return (bool) $reset_allowed; |
|
| 1323 | - |
|
| 1324 | - } |
|
| 1276 | + } // End sensei_quiz_action_buttons() |
|
| 1277 | + |
|
| 1278 | + /** |
|
| 1279 | + * Fetch the quiz grade |
|
| 1280 | + * |
|
| 1281 | + * @since 1.9.0 |
|
| 1282 | + * |
|
| 1283 | + * @param int $lesson_id |
|
| 1284 | + * @param int $user_id |
|
| 1285 | + * |
|
| 1286 | + * @return double $user_quiz_grade |
|
| 1287 | + */ |
|
| 1288 | + public static function get_user_quiz_grade( $lesson_id, $user_id ){ |
|
| 1289 | + |
|
| 1290 | + // get the quiz grade |
|
| 1291 | + $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id ); |
|
| 1292 | + $user_quiz_grade = 0; |
|
| 1293 | + if( isset( $user_lesson_status->comment_ID ) ) { |
|
| 1294 | + $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true ); |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + return (double) $user_quiz_grade; |
|
| 1298 | + |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + /** |
|
| 1302 | + * Check the quiz reset property for a given lesson's quiz. |
|
| 1303 | + * |
|
| 1304 | + * The data is stored on the quiz but going forward the quiz post |
|
| 1305 | + * type will be retired, hence the lesson_id is a require parameter. |
|
| 1306 | + * |
|
| 1307 | + * @since 1.9.0 |
|
| 1308 | + * |
|
| 1309 | + * @param int $lesson_id |
|
| 1310 | + * @return bool |
|
| 1311 | + */ |
|
| 1312 | + public static function is_reset_allowed( $lesson_id ){ |
|
| 1313 | + |
|
| 1314 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1315 | + |
|
| 1316 | + $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 1317 | + //backwards compatibility |
|
| 1318 | + if( 'on' == $reset_allowed ) { |
|
| 1319 | + $reset_allowed = 1; |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + return (bool) $reset_allowed; |
|
| 1323 | + |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | 1326 | } // End Class WooThemes_Sensei_Quiz |
| 1327 | 1327 | |
@@ -19,63 +19,63 @@ discard block |
||
| 19 | 19 | * @since 1.0.0 |
| 20 | 20 | */ |
| 21 | 21 | public function __construct () { |
| 22 | - parent::__construct(); // Required in extended classes. |
|
| 22 | + parent::__construct(); // Required in extended classes. |
|
| 23 | 23 | |
| 24 | - $this->token = 'woothemes-sensei-settings'; |
|
| 25 | - add_action('init', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
| 24 | + $this->token = 'woothemes-sensei-settings'; |
|
| 25 | + add_action('init', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
| 26 | 26 | |
| 27 | - // Setup Admin Settings data |
|
| 28 | - if ( is_admin() ) { |
|
| 27 | + // Setup Admin Settings data |
|
| 28 | + if ( is_admin() ) { |
|
| 29 | 29 | |
| 30 | - $this->has_tabs = true; |
|
| 31 | - $this->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
| 32 | - $this->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
| 33 | - $this->page_slug = 'woothemes-sensei-settings'; |
|
| 30 | + $this->has_tabs = true; |
|
| 31 | + $this->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
| 32 | + $this->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
| 33 | + $this->page_slug = 'woothemes-sensei-settings'; |
|
| 34 | 34 | |
| 35 | - } // End If Statement |
|
| 35 | + } // End If Statement |
|
| 36 | 36 | |
| 37 | - $this->register_hook_listener(); |
|
| 38 | - $this->get_settings(); |
|
| 37 | + $this->register_hook_listener(); |
|
| 38 | + $this->get_settings(); |
|
| 39 | 39 | |
| 40 | 40 | } // End __construct() |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Get settings value |
|
| 44 | - * |
|
| 45 | - * @since 1.9.0 |
|
| 46 | - * @param string $setting_name |
|
| 47 | - * @return mixed |
|
| 48 | - */ |
|
| 49 | - public function get( $setting_name ){ |
|
| 42 | + /** |
|
| 43 | + * Get settings value |
|
| 44 | + * |
|
| 45 | + * @since 1.9.0 |
|
| 46 | + * @param string $setting_name |
|
| 47 | + * @return mixed |
|
| 48 | + */ |
|
| 49 | + public function get( $setting_name ){ |
|
| 50 | 50 | |
| 51 | - if( isset( $this->settings[ $setting_name ] ) ){ |
|
| 51 | + if( isset( $this->settings[ $setting_name ] ) ){ |
|
| 52 | 52 | |
| 53 | - return $this->settings[ $setting_name ]; |
|
| 53 | + return $this->settings[ $setting_name ]; |
|
| 54 | 54 | |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return false; |
|
| 58 | - } |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @since 1.9.0 |
|
| 62 | - * |
|
| 63 | - * @param $setting |
|
| 64 | - * @param $new_value |
|
| 65 | - */ |
|
| 66 | - public function set( $setting, $new_value ){ |
|
| 60 | + /** |
|
| 61 | + * @since 1.9.0 |
|
| 62 | + * |
|
| 63 | + * @param $setting |
|
| 64 | + * @param $new_value |
|
| 65 | + */ |
|
| 66 | + public function set( $setting, $new_value ){ |
|
| 67 | 67 | |
| 68 | - $settings = get_option( $this->token, array() ); |
|
| 68 | + $settings = get_option( $this->token, array() ); |
|
| 69 | 69 | |
| 70 | - if( isset( $settings[ $setting ] ) ){ |
|
| 70 | + if( isset( $settings[ $setting ] ) ){ |
|
| 71 | 71 | |
| 72 | - $settings[ $setting ] = $new_value; |
|
| 73 | - return update_option( $this->token,$settings ); |
|
| 72 | + $settings[ $setting ] = $new_value; |
|
| 73 | + return update_option( $this->token,$settings ); |
|
| 74 | 74 | |
| 75 | - } |
|
| 76 | - return false; |
|
| 75 | + } |
|
| 76 | + return false; |
|
| 77 | 77 | |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Register the settings screen within the WordPress admin. |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $complete_settings = array( 'passed' => __( 'Once all the course lessons have been completed', 'woothemes-sensei' ), 'complete' => __( 'At any time (by clicking the \'Complete Course\' button)', 'woothemes-sensei' ) ); |
| 164 | 164 | $course_display_settings = array( 'excerpt' => __( 'Course Excerpt', 'woothemes-sensei' ), 'full' => __( 'Full Course Content', 'woothemes-sensei' ) ); |
| 165 | 165 | |
| 166 | - $fields = array(); |
|
| 166 | + $fields = array(); |
|
| 167 | 167 | |
| 168 | 168 | $fields['access_permission'] = array( |
| 169 | 169 | 'name' => __( 'Access Permissions', 'woothemes-sensei' ), |
@@ -225,9 +225,9 @@ discard block |
||
| 225 | 225 | 'section' => 'default-settings' |
| 226 | 226 | ); |
| 227 | 227 | |
| 228 | - // Course Settings |
|
| 228 | + // Course Settings |
|
| 229 | 229 | |
| 230 | - $fields['course_completion'] = array( |
|
| 230 | + $fields['course_completion'] = array( |
|
| 231 | 231 | 'name' => __( 'Courses are complete:', 'woothemes-sensei' ), |
| 232 | 232 | 'description' => __( 'This will determine when courses are marked as complete.', 'woothemes-sensei' ), |
| 233 | 233 | 'type' => 'select', |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | 'options' => $complete_settings |
| 238 | 238 | ); |
| 239 | 239 | |
| 240 | - $fields['course_author'] = array( |
|
| 240 | + $fields['course_author'] = array( |
|
| 241 | 241 | 'name' => __( 'Display Course Author', 'woothemes-sensei' ), |
| 242 | 242 | 'description' => __( 'Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei' ), |
| 243 | 243 | 'type' => 'checkbox', |
@@ -465,10 +465,10 @@ discard block |
||
| 465 | 465 | ); |
| 466 | 466 | |
| 467 | 467 | $teacher_email_options = array( |
| 468 | - 'teacher-started-course' => __( 'A learner starts their course', 'woothemes-sensei' ), |
|
| 469 | - 'teacher-completed-course' => __( 'A learner completes their course', 'woothemes-sensei' ), |
|
| 470 | - 'teacher-completed-lesson' => __( 'A learner completes a lesson', 'woothemes-sensei' ), |
|
| 471 | - 'teacher-quiz-submitted' => __( 'A learner submits a quiz for grading', 'woothemes-sensei' ), |
|
| 468 | + 'teacher-started-course' => __( 'A learner starts their course', 'woothemes-sensei' ), |
|
| 469 | + 'teacher-completed-course' => __( 'A learner completes their course', 'woothemes-sensei' ), |
|
| 470 | + 'teacher-completed-lesson' => __( 'A learner completes a lesson', 'woothemes-sensei' ), |
|
| 471 | + 'teacher-quiz-submitted' => __( 'A learner submits a quiz for grading', 'woothemes-sensei' ), |
|
| 472 | 472 | 'teacher-new-message' => __( 'A learner sends a private message to a teacher', 'woothemes-sensei' ), |
| 473 | 473 | ); |
| 474 | 474 | |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | |
| 578 | 578 | if ( Sensei_WC::is_woocommerce_present() ) { |
| 579 | 579 | // WooCommerce Settings |
| 580 | - $fields['woocommerce_enabled'] = array( |
|
| 580 | + $fields['woocommerce_enabled'] = array( |
|
| 581 | 581 | 'name' => __( 'Enable WooCommerce Courses', 'woothemes-sensei' ), |
| 582 | 582 | 'description' => __( 'Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei' ), |
| 583 | 583 | 'type' => 'checkbox', |
@@ -665,14 +665,14 @@ discard block |
||
| 665 | 665 | $page_items[] = __( 'Select a Page:', 'woothemes-sensei' ); |
| 666 | 666 | |
| 667 | 667 | foreach ( $pages_split as $k => $v ) { |
| 668 | - $id = ''; |
|
| 669 | - // Get the ID value. |
|
| 670 | - preg_match( '/value="(.*?)"/i', $v, $matches ); |
|
| 671 | - |
|
| 672 | - if ( isset( $matches[1] ) ) { |
|
| 673 | - $id = $matches[1]; |
|
| 674 | - $page_items[$id] = trim( strip_tags( $v ) ); |
|
| 675 | - } // End If Statement |
|
| 668 | + $id = ''; |
|
| 669 | + // Get the ID value. |
|
| 670 | + preg_match( '/value="(.*?)"/i', $v, $matches ); |
|
| 671 | + |
|
| 672 | + if ( isset( $matches[1] ) ) { |
|
| 673 | + $id = $matches[1]; |
|
| 674 | + $page_items[$id] = trim( strip_tags( $v ) ); |
|
| 675 | + } // End If Statement |
|
| 676 | 676 | } // End For Loop |
| 677 | 677 | |
| 678 | 678 | $pages_array = $page_items; |
@@ -689,22 +689,22 @@ discard block |
||
| 689 | 689 | Sensei_Language_Pack_Manager::messages(); |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - /** |
|
| 693 | - * Flush the rewrite rules after the settings have been updated. |
|
| 694 | - * This is to ensure that the |
|
| 695 | - * |
|
| 696 | - * @since 1.9.0 |
|
| 697 | - */ |
|
| 698 | - public static function flush_rewrite_rules(){ |
|
| 692 | + /** |
|
| 693 | + * Flush the rewrite rules after the settings have been updated. |
|
| 694 | + * This is to ensure that the |
|
| 695 | + * |
|
| 696 | + * @since 1.9.0 |
|
| 697 | + */ |
|
| 698 | + public static function flush_rewrite_rules(){ |
|
| 699 | 699 | |
| 700 | - if ( isset( $_POST[ 'option_page' ] ) && 'woothemes-sensei-settings' == $_POST[ 'option_page' ] |
|
| 701 | - && isset( $_POST[ 'action' ] ) && 'update' == $_POST[ 'action' ] ) { |
|
| 700 | + if ( isset( $_POST[ 'option_page' ] ) && 'woothemes-sensei-settings' == $_POST[ 'option_page' ] |
|
| 701 | + && isset( $_POST[ 'action' ] ) && 'update' == $_POST[ 'action' ] ) { |
|
| 702 | 702 | |
| 703 | - Sensei()->initiate_rewrite_rules_flush(); |
|
| 703 | + Sensei()->initiate_rewrite_rules_flush(); |
|
| 704 | 704 | |
| 705 | - } |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - }//end flush_cache |
|
| 707 | + }//end flush_cache |
|
| 708 | 708 | } // End Class |
| 709 | 709 | |
| 710 | 710 | /** |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Check if WooCommerce is present. |
| 28 | - * |
|
| 29 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
| 28 | + * |
|
| 29 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
| 30 | 30 | * @access public |
| 31 | 31 | * @since 1.0.2 |
| 32 | 32 | * @static |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public static function sensei_is_woocommerce_present () { |
| 36 | 36 | |
| 37 | - return Sensei_WC::is_woocommerce_present(); |
|
| 37 | + return Sensei_WC::is_woocommerce_present(); |
|
| 38 | 38 | |
| 39 | 39 | } // End sensei_is_woocommerce_present() |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Check if WooCommerce is active. |
| 43 | - * |
|
| 44 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
| 43 | + * |
|
| 44 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
| 45 | 45 | * @access public |
| 46 | 46 | * @since 1.0.2 |
| 47 | 47 | * @static |
@@ -186,15 +186,15 @@ discard block |
||
| 186 | 186 | add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - //Get the comments |
|
| 190 | - /** |
|
| 191 | - * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 192 | - * |
|
| 193 | - * It runs while getting the comments for the given request. |
|
| 194 | - * |
|
| 195 | - * @param int|array $comments |
|
| 196 | - */ |
|
| 197 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 189 | + //Get the comments |
|
| 190 | + /** |
|
| 191 | + * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
| 192 | + * |
|
| 193 | + * It runs while getting the comments for the given request. |
|
| 194 | + * |
|
| 195 | + * @param int|array $comments |
|
| 196 | + */ |
|
| 197 | + $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
| 198 | 198 | |
| 199 | 199 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
| 200 | 200 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
@@ -279,18 +279,18 @@ discard block |
||
| 279 | 279 | return $dataset_changes; |
| 280 | 280 | } // End sensei_delete_activities() |
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Delete all activity for specified user |
|
| 284 | - * @access public |
|
| 282 | + /** |
|
| 283 | + * Delete all activity for specified user |
|
| 284 | + * @access public |
|
| 285 | 285 | * @since 1.5.0 |
| 286 | - * @param integer $user_id User ID |
|
| 287 | - * @return boolean |
|
| 288 | - */ |
|
| 289 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 286 | + * @param integer $user_id User ID |
|
| 287 | + * @return boolean |
|
| 288 | + */ |
|
| 289 | + public static function delete_all_user_activity( $user_id = 0 ) { |
|
| 290 | 290 | |
| 291 | - $dataset_changes = false; |
|
| 291 | + $dataset_changes = false; |
|
| 292 | 292 | |
| 293 | - if( $user_id ) { |
|
| 293 | + if( $user_id ) { |
|
| 294 | 294 | |
| 295 | 295 | $activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
| 296 | 296 | |
@@ -335,35 +335,35 @@ discard block |
||
| 335 | 335 | return $activity_value; |
| 336 | 336 | } // End sensei_get_activity_value() |
| 337 | 337 | |
| 338 | - /** |
|
| 339 | - * Checks if a user (by email) has bought an item. |
|
| 340 | - * |
|
| 341 | - * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
| 342 | - * @access public |
|
| 343 | - * @since 1.0.0 |
|
| 344 | - * @param string $customer_email |
|
| 345 | - * @param int $user_id |
|
| 346 | - * @param int $product_id |
|
| 347 | - * @return bool |
|
| 348 | - */ |
|
| 349 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 338 | + /** |
|
| 339 | + * Checks if a user (by email) has bought an item. |
|
| 340 | + * |
|
| 341 | + * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
| 342 | + * @access public |
|
| 343 | + * @since 1.0.0 |
|
| 344 | + * @param string $customer_email |
|
| 345 | + * @param int $user_id |
|
| 346 | + * @param int $product_id |
|
| 347 | + * @return bool |
|
| 348 | + */ |
|
| 349 | + public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
| 350 | 350 | |
| 351 | - $emails = array(); |
|
| 351 | + $emails = array(); |
|
| 352 | 352 | |
| 353 | - if ( $user_id ) { |
|
| 354 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 355 | - $emails[] = $user->user_email; |
|
| 356 | - } |
|
| 353 | + if ( $user_id ) { |
|
| 354 | + $user = get_user_by( 'id', intval( $user_id ) ); |
|
| 355 | + $emails[] = $user->user_email; |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - if ( is_email( $customer_email ) ) |
|
| 359 | - $emails[] = $customer_email; |
|
| 358 | + if ( is_email( $customer_email ) ) |
|
| 359 | + $emails[] = $customer_email; |
|
| 360 | 360 | |
| 361 | - if ( sizeof( $emails ) == 0 ) |
|
| 362 | - return false; |
|
| 361 | + if ( sizeof( $emails ) == 0 ) |
|
| 362 | + return false; |
|
| 363 | 363 | |
| 364 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 364 | + return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
| 365 | 365 | |
| 366 | - } // End sensei_customer_bought_product() |
|
| 366 | + } // End sensei_customer_bought_product() |
|
| 367 | 367 | |
| 368 | 368 | /** |
| 369 | 369 | * Load the WordPress rich text editor |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | /** |
| 400 | 400 | * Save quiz answers submitted by users |
| 401 | 401 | * @param array $submitted User's quiz answers |
| 402 | - * @param int $user_id |
|
| 402 | + * @param int $user_id |
|
| 403 | 403 | * @return boolean Whether the answers were saved or not |
| 404 | 404 | */ |
| 405 | 405 | public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) { |
@@ -468,72 +468,72 @@ discard block |
||
| 468 | 468 | |
| 469 | 469 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
| 470 | 470 | |
| 471 | - /** |
|
| 472 | - * Filter the data array for the Sensei wp_handle_upload function call |
|
| 473 | - * |
|
| 474 | - * This filter was mainly added for Unit Testing purposes. |
|
| 475 | - * |
|
| 476 | - * @since 1.7.4 |
|
| 477 | - * |
|
| 478 | - * @param array $file_upload_args { |
|
| 479 | - * array of current values |
|
| 480 | - * |
|
| 481 | - * @type string test_form set to false by default |
|
| 482 | - * } |
|
| 483 | - */ |
|
| 484 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 485 | - |
|
| 486 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 487 | - |
|
| 488 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 489 | - return false; |
|
| 490 | - } else { |
|
| 471 | + /** |
|
| 472 | + * Filter the data array for the Sensei wp_handle_upload function call |
|
| 473 | + * |
|
| 474 | + * This filter was mainly added for Unit Testing purposes. |
|
| 475 | + * |
|
| 476 | + * @since 1.7.4 |
|
| 477 | + * |
|
| 478 | + * @param array $file_upload_args { |
|
| 479 | + * array of current values |
|
| 480 | + * |
|
| 481 | + * @type string test_form set to false by default |
|
| 482 | + * } |
|
| 483 | + */ |
|
| 484 | + $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
| 485 | + |
|
| 486 | + $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
| 487 | + |
|
| 488 | + if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
| 489 | + return false; |
|
| 490 | + } else { |
|
| 491 | 491 | |
| 492 | - $filename = $file_return['file']; |
|
| 492 | + $filename = $file_return['file']; |
|
| 493 | 493 | |
| 494 | - $attachment = array( |
|
| 495 | - 'post_mime_type' => $file_return['type'], |
|
| 496 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 497 | - 'post_content' => '', |
|
| 498 | - 'post_status' => 'inherit', |
|
| 499 | - 'guid' => $file_return['url'] |
|
| 500 | - ); |
|
| 494 | + $attachment = array( |
|
| 495 | + 'post_mime_type' => $file_return['type'], |
|
| 496 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 497 | + 'post_content' => '', |
|
| 498 | + 'post_status' => 'inherit', |
|
| 499 | + 'guid' => $file_return['url'] |
|
| 500 | + ); |
|
| 501 | 501 | |
| 502 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 502 | + $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 503 | 503 | |
| 504 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 505 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 506 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 504 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
| 505 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 506 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 507 | 507 | |
| 508 | - if( 0 < intval( $attachment_id ) ) { |
|
| 509 | - return $attachment_id; |
|
| 510 | - } |
|
| 511 | - } |
|
| 508 | + if( 0 < intval( $attachment_id ) ) { |
|
| 509 | + return $attachment_id; |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | 512 | |
| 513 | - return false; |
|
| 513 | + return false; |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
| 517 | 517 | * Grade quiz automatically |
| 518 | - * |
|
| 519 | - * This function grades each question automatically if the are auto gradable. |
|
| 520 | - * It store all question grades. |
|
| 521 | - * |
|
| 522 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 523 | - * |
|
| 518 | + * |
|
| 519 | + * This function grades each question automatically if the are auto gradable. |
|
| 520 | + * It store all question grades. |
|
| 521 | + * |
|
| 522 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
| 523 | + * |
|
| 524 | 524 | * @param integer $quiz_id ID of quiz |
| 525 | 525 | * @param array $submitted questions id ans answers { |
| 526 | - * @type int $question_id |
|
| 527 | - * @type mixed $answer |
|
| 528 | - * } |
|
| 526 | + * @type int $question_id |
|
| 527 | + * @type mixed $answer |
|
| 528 | + * } |
|
| 529 | 529 | * @param integer $total_questions Total questions in quiz (not used) |
| 530 | - * @param string $quiz_grade_type Optional defaults to auto |
|
| 531 | - * |
|
| 530 | + * @param string $quiz_grade_type Optional defaults to auto |
|
| 531 | + * |
|
| 532 | 532 | * @return int $quiz_grade total sum of all question grades |
| 533 | 533 | */ |
| 534 | 534 | public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
| 535 | 535 | |
| 536 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 536 | + return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
| 537 | 537 | |
| 538 | 538 | } // End sensei_grade_quiz_auto() |
| 539 | 539 | |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | * @param integer $quiz_id ID of quiz |
| 543 | 543 | * @param integer $grade Grade received |
| 544 | 544 | * @param integer $user_id ID of user being graded |
| 545 | - * @param string $quiz_grade_type default 'auto' |
|
| 545 | + * @param string $quiz_grade_type default 'auto' |
|
| 546 | 546 | * @return boolean |
| 547 | 547 | */ |
| 548 | 548 | public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
@@ -566,21 +566,21 @@ discard block |
||
| 566 | 566 | |
| 567 | 567 | /** |
| 568 | 568 | * Grade question automatically |
| 569 | - * |
|
| 570 | - * This function checks the question typ and then grades it accordingly. |
|
| 571 | - * |
|
| 572 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 573 | - * |
|
| 569 | + * |
|
| 570 | + * This function checks the question typ and then grades it accordingly. |
|
| 571 | + * |
|
| 572 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
| 573 | + * |
|
| 574 | 574 | * @param integer $question_id |
| 575 | - * @param string $question_type of the standard Sensei question types |
|
| 575 | + * @param string $question_type of the standard Sensei question types |
|
| 576 | 576 | * @param string $answer |
| 577 | - * @param int $user_id |
|
| 578 | - * |
|
| 577 | + * @param int $user_id |
|
| 578 | + * |
|
| 579 | 579 | * @return int $question_grade |
| 580 | 580 | */ |
| 581 | 581 | public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
| 582 | 582 | |
| 583 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 583 | + return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
| 584 | 584 | |
| 585 | 585 | } // end sensei_grade_question_auto |
| 586 | 586 | |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * Grade question |
| 589 | 589 | * @param integer $question_id ID of question |
| 590 | 590 | * @param integer $grade Grade received |
| 591 | - * @param int $user_id |
|
| 591 | + * @param int $user_id |
|
| 592 | 592 | * @return boolean |
| 593 | 593 | */ |
| 594 | 594 | public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
@@ -627,35 +627,35 @@ discard block |
||
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | |
| 630 | - /** |
|
| 631 | - * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 632 | - * |
|
| 633 | - * @since 1.7.4 |
|
| 634 | - * |
|
| 635 | - * @param integer $user_id |
|
| 636 | - * @param integer $lesson_id |
|
| 637 | - * @param bool $complete |
|
| 638 | - * |
|
| 639 | - * @return mixed boolean or comment_ID |
|
| 640 | - */ |
|
| 641 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 630 | + /** |
|
| 631 | + * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
| 632 | + * |
|
| 633 | + * @since 1.7.4 |
|
| 634 | + * |
|
| 635 | + * @param integer $user_id |
|
| 636 | + * @param integer $lesson_id |
|
| 637 | + * @param bool $complete |
|
| 638 | + * |
|
| 639 | + * @return mixed boolean or comment_ID |
|
| 640 | + */ |
|
| 641 | + public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
| 642 | 642 | |
| 643 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 643 | + return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
| 644 | 644 | |
| 645 | - }// end user_start_lesson() |
|
| 645 | + }// end user_start_lesson() |
|
| 646 | 646 | |
| 647 | 647 | /** |
| 648 | 648 | * Mark a lesson as started for user |
| 649 | - * |
|
| 650 | - * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 651 | - * |
|
| 652 | - * @since 1.6.0 |
|
| 653 | - * |
|
| 649 | + * |
|
| 650 | + * Will also start the lesson course for the user if the user hans't started taking it already. |
|
| 651 | + * |
|
| 652 | + * @since 1.6.0 |
|
| 653 | + * |
|
| 654 | 654 | * @param integer $lesson_id ID of lesson |
| 655 | 655 | * @param int| string $user_id default 0 |
| 656 | - * @param bool $complete default false |
|
| 657 | - * |
|
| 658 | - * @return mixed boolean or comment_ID |
|
| 656 | + * @param bool $complete default false |
|
| 657 | + * |
|
| 658 | + * @return mixed boolean or comment_ID |
|
| 659 | 659 | */ |
| 660 | 660 | public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
| 661 | 661 | |
@@ -701,21 +701,21 @@ discard block |
||
| 701 | 701 | $metadata['start'] = current_time('mysql'); |
| 702 | 702 | $activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
| 703 | 703 | |
| 704 | - } else { |
|
| 704 | + } else { |
|
| 705 | 705 | |
| 706 | - // if users is already taking the lesson and the status changes to complete update it |
|
| 707 | - $current_user_activity = get_comment($activity_logged); |
|
| 708 | - if( $status=='complete' && |
|
| 709 | - $status != $current_user_activity->comment_approved ){ |
|
| 706 | + // if users is already taking the lesson and the status changes to complete update it |
|
| 707 | + $current_user_activity = get_comment($activity_logged); |
|
| 708 | + if( $status=='complete' && |
|
| 709 | + $status != $current_user_activity->comment_approved ){ |
|
| 710 | 710 | |
| 711 | - $comment = array(); |
|
| 712 | - $comment['comment_ID'] = $activity_logged; |
|
| 713 | - $comment['comment_approved'] = $status; |
|
| 714 | - wp_update_comment( $comment ); |
|
| 711 | + $comment = array(); |
|
| 712 | + $comment['comment_ID'] = $activity_logged; |
|
| 713 | + $comment['comment_approved'] = $status; |
|
| 714 | + wp_update_comment( $comment ); |
|
| 715 | 715 | |
| 716 | - } |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - } |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | 720 | if ( $complete ) { |
| 721 | 721 | // Run this *after* the lesson status has been created/updated |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | /** |
| 862 | 862 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
| 863 | 863 | * |
| 864 | - * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 864 | + * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
| 865 | 865 | * @param mixed $question |
| 866 | 866 | * @param int $user_id |
| 867 | 867 | * @return string |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | * Add answer notes to question |
| 922 | 922 | * @param integer $question_id ID of question |
| 923 | 923 | * @param integer $user_id ID of user |
| 924 | - * @param string $notes |
|
| 924 | + * @param string $notes |
|
| 925 | 925 | * @return boolean |
| 926 | 926 | */ |
| 927 | 927 | public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
@@ -979,17 +979,17 @@ discard block |
||
| 979 | 979 | * @return void |
| 980 | 980 | */ |
| 981 | 981 | public static function sort_array_by_key( $array, $key ) { |
| 982 | - $sorter = array(); |
|
| 983 | - $ret = array(); |
|
| 984 | - reset( $array ); |
|
| 985 | - foreach ( $array as $ii => $va ) { |
|
| 986 | - $sorter[$ii] = $va[$key]; |
|
| 987 | - } // End For Loop |
|
| 988 | - asort( $sorter ); |
|
| 989 | - foreach ( $sorter as $ii => $va ) { |
|
| 990 | - $ret[$ii] = $array[$ii]; |
|
| 991 | - } // End For Loop |
|
| 992 | - $array = $ret; |
|
| 982 | + $sorter = array(); |
|
| 983 | + $ret = array(); |
|
| 984 | + reset( $array ); |
|
| 985 | + foreach ( $array as $ii => $va ) { |
|
| 986 | + $sorter[$ii] = $va[$key]; |
|
| 987 | + } // End For Loop |
|
| 988 | + asort( $sorter ); |
|
| 989 | + foreach ( $sorter as $ii => $va ) { |
|
| 990 | + $ret[$ii] = $array[$ii]; |
|
| 991 | + } // End For Loop |
|
| 992 | + $array = $ret; |
|
| 993 | 993 | } // End sort_array_by_key() |
| 994 | 994 | |
| 995 | 995 | /** |
@@ -1002,21 +1002,21 @@ discard block |
||
| 1002 | 1002 | $questions_array = array(); |
| 1003 | 1003 | if ( 0 < $quiz_id ) { |
| 1004 | 1004 | $question_args = array( 'post_type' => 'question', |
| 1005 | - 'posts_per_page' => -1, |
|
| 1006 | - 'orderby' => 'ID', |
|
| 1007 | - 'order' => 'ASC', |
|
| 1008 | - 'meta_query' => array( |
|
| 1005 | + 'posts_per_page' => -1, |
|
| 1006 | + 'orderby' => 'ID', |
|
| 1007 | + 'order' => 'ASC', |
|
| 1008 | + 'meta_query' => array( |
|
| 1009 | 1009 | array( |
| 1010 | 1010 | 'key' => '_quiz_id', |
| 1011 | 1011 | 'value' => $quiz_id, |
| 1012 | 1012 | ) |
| 1013 | 1013 | ), |
| 1014 | - 'post_status' => 'any', |
|
| 1015 | - 'suppress_filters' => 0 |
|
| 1016 | - ); |
|
| 1017 | - $questions_array = get_posts( $question_args ); |
|
| 1018 | - } // End If Statement |
|
| 1019 | - return $questions_array; |
|
| 1014 | + 'post_status' => 'any', |
|
| 1015 | + 'suppress_filters' => 0 |
|
| 1016 | + ); |
|
| 1017 | + $questions_array = get_posts( $question_args ); |
|
| 1018 | + } // End If Statement |
|
| 1019 | + return $questions_array; |
|
| 1020 | 1020 | } // End lesson_quiz_questions() |
| 1021 | 1021 | |
| 1022 | 1022 | /** |
@@ -1174,7 +1174,7 @@ discard block |
||
| 1174 | 1174 | * Set the status message displayed to the user for a quiz |
| 1175 | 1175 | * @param integer $lesson_id ID of quiz lesson |
| 1176 | 1176 | * @param integer $user_id ID of user |
| 1177 | - * @param bool $is_lesson |
|
| 1177 | + * @param bool $is_lesson |
|
| 1178 | 1178 | * @return array Status code and message |
| 1179 | 1179 | */ |
| 1180 | 1180 | public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
@@ -1257,20 +1257,20 @@ discard block |
||
| 1257 | 1257 | } |
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | - // add next lesson button |
|
| 1261 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1262 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1260 | + // add next lesson button |
|
| 1261 | + $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
| 1262 | + $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
| 1263 | 1263 | |
| 1264 | - // Output HTML |
|
| 1265 | - if ( ( 0 < $next_lesson_id ) ) { |
|
| 1266 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1267 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1268 | - .'</a>'; |
|
| 1264 | + // Output HTML |
|
| 1265 | + if ( ( 0 < $next_lesson_id ) ) { |
|
| 1266 | + $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
| 1267 | + . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
| 1268 | + .'</a>'; |
|
| 1269 | 1269 | |
| 1270 | - } |
|
| 1270 | + } |
|
| 1271 | 1271 | |
| 1272 | 1272 | } |
| 1273 | - // Lesson/Quiz not complete |
|
| 1273 | + // Lesson/Quiz not complete |
|
| 1274 | 1274 | else { |
| 1275 | 1275 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
| 1276 | 1276 | if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
| 1311 | 1311 | |
| 1312 | 1312 | if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
| 1313 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1313 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
| 1314 | 1314 | $extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '</a></p>'; |
| 1315 | 1315 | } |
| 1316 | 1316 | |
@@ -1368,9 +1368,9 @@ discard block |
||
| 1368 | 1368 | $user_id = get_current_user_id(); |
| 1369 | 1369 | } |
| 1370 | 1370 | |
| 1371 | - if( ! $user_id > 0 ){ |
|
| 1372 | - return false; |
|
| 1373 | - } |
|
| 1371 | + if( ! $user_id > 0 ){ |
|
| 1372 | + return false; |
|
| 1373 | + } |
|
| 1374 | 1374 | |
| 1375 | 1375 | $user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
| 1376 | 1376 | if( $user_course_status_id ) { |
@@ -1494,7 +1494,7 @@ discard block |
||
| 1494 | 1494 | * Check if a user has completed a course or not |
| 1495 | 1495 | * |
| 1496 | 1496 | * @param int | WP_Post | WP_Comment $course course_id or sensei_course_status entry |
| 1497 | - * |
|
| 1497 | + * |
|
| 1498 | 1498 | * @param int $user_id |
| 1499 | 1499 | * @return boolean |
| 1500 | 1500 | */ |
@@ -1512,14 +1512,14 @@ discard block |
||
| 1512 | 1512 | $user_id = get_current_user_id(); |
| 1513 | 1513 | } |
| 1514 | 1514 | |
| 1515 | - if( is_a( $course, 'WP_Post' ) ){ |
|
| 1516 | - $course = $course->ID; |
|
| 1517 | - } |
|
| 1515 | + if( is_a( $course, 'WP_Post' ) ){ |
|
| 1516 | + $course = $course->ID; |
|
| 1517 | + } |
|
| 1518 | 1518 | |
| 1519 | 1519 | $user_course_status = Sensei_Utils::user_course_status( $course , $user_id ); |
| 1520 | 1520 | if( isset( $user_course_status->comment_approved ) ){ |
| 1521 | - $user_course_status = $user_course_status->comment_approved; |
|
| 1522 | - } |
|
| 1521 | + $user_course_status = $user_course_status->comment_approved; |
|
| 1522 | + } |
|
| 1523 | 1523 | |
| 1524 | 1524 | } |
| 1525 | 1525 | if( $user_course_status && 'complete' == $user_course_status ) { |
@@ -1544,11 +1544,11 @@ discard block |
||
| 1544 | 1544 | $user_id = get_current_user_id(); |
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | - $activity_args = array( |
|
| 1548 | - 'post_id' => $lesson_id, |
|
| 1549 | - 'user_id' => $user_id, |
|
| 1550 | - 'type' => 'sensei_lesson_status', |
|
| 1551 | - 'field' => 'comment_ID' ); |
|
| 1547 | + $activity_args = array( |
|
| 1548 | + 'post_id' => $lesson_id, |
|
| 1549 | + 'user_id' => $user_id, |
|
| 1550 | + 'type' => 'sensei_lesson_status', |
|
| 1551 | + 'field' => 'comment_ID' ); |
|
| 1552 | 1552 | |
| 1553 | 1553 | $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
| 1554 | 1554 | if( $user_lesson_status_id ) { |
@@ -1561,7 +1561,7 @@ discard block |
||
| 1561 | 1561 | /** |
| 1562 | 1562 | * Check if a user has completed a lesson or not |
| 1563 | 1563 | * |
| 1564 | - * @uses Sensei() |
|
| 1564 | + * @uses Sensei() |
|
| 1565 | 1565 | * @param mixed $lesson lesson_id or sensei_lesson_status entry |
| 1566 | 1566 | * @param int $user_id |
| 1567 | 1567 | * @return boolean |
@@ -1582,10 +1582,10 @@ discard block |
||
| 1582 | 1582 | $user_id = get_current_user_id(); |
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | - // the user is not logged in |
|
| 1586 | - if( ! $user_id > 0 ){ |
|
| 1587 | - return false; |
|
| 1588 | - } |
|
| 1585 | + // the user is not logged in |
|
| 1586 | + if( ! $user_id > 0 ){ |
|
| 1587 | + return false; |
|
| 1588 | + } |
|
| 1589 | 1589 | $_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
| 1590 | 1590 | |
| 1591 | 1591 | if ( $_user_lesson_status ) { |
@@ -1664,9 +1664,9 @@ discard block |
||
| 1664 | 1664 | */ |
| 1665 | 1665 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
| 1666 | 1666 | |
| 1667 | - if( ! $user_id ) { |
|
| 1668 | - $user_id = get_current_user_id(); |
|
| 1669 | - } |
|
| 1667 | + if( ! $user_id ) { |
|
| 1668 | + $user_id = get_current_user_id(); |
|
| 1669 | + } |
|
| 1670 | 1670 | |
| 1671 | 1671 | if( $lesson_id > 0 && $user_id > 0 ) { |
| 1672 | 1672 | |
@@ -1717,12 +1717,12 @@ discard block |
||
| 1717 | 1717 | * Sets the status for the lesson |
| 1718 | 1718 | * |
| 1719 | 1719 | * @since 1.7.0 |
| 1720 | - * |
|
| 1720 | + * |
|
| 1721 | 1721 | * @param int|string $user_id |
| 1722 | 1722 | * @param int|string $lesson_id |
| 1723 | 1723 | * @param string $status |
| 1724 | 1724 | * @param array $metadata |
| 1725 | - * |
|
| 1725 | + * |
|
| 1726 | 1726 | * @return mixed false or comment_ID |
| 1727 | 1727 | */ |
| 1728 | 1728 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
@@ -1838,7 +1838,7 @@ discard block |
||
| 1838 | 1838 | /** |
| 1839 | 1839 | * Adjust the comment query to be faster on the database, used by Analysis admin |
| 1840 | 1840 | * @since 1.7.0 |
| 1841 | - * @param array $pieces |
|
| 1841 | + * @param array $pieces |
|
| 1842 | 1842 | * @return array $pieces |
| 1843 | 1843 | */ |
| 1844 | 1844 | public static function comment_total_sum_meta_value_filter( $pieces ) { |
@@ -1873,360 +1873,360 @@ discard block |
||
| 1873 | 1873 | return $pieces; |
| 1874 | 1874 | } |
| 1875 | 1875 | |
| 1876 | - /** |
|
| 1877 | - * |
|
| 1878 | - * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1879 | - * @since 1.7.4 |
|
| 1880 | - * |
|
| 1881 | - * @param string $data_key maximum 39 characters allowed |
|
| 1882 | - * @param int $post_id |
|
| 1883 | - * @param mixed $value |
|
| 1884 | - * @param int $user_id |
|
| 1885 | - * |
|
| 1886 | - * @return bool $success |
|
| 1887 | - */ |
|
| 1888 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1889 | - |
|
| 1890 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1891 | - |
|
| 1892 | - }// end add_user_data |
|
| 1893 | - |
|
| 1894 | - /** |
|
| 1895 | - * add user specific data to the passed in sensei post type id |
|
| 1896 | - * |
|
| 1897 | - * This function saves comment meta on the users current status. If no status is available |
|
| 1898 | - * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1899 | - * |
|
| 1900 | - * @since 1.7.4 |
|
| 1901 | - * |
|
| 1902 | - * @param string $data_key maximum 39 characters allowed |
|
| 1903 | - * @param int $post_id |
|
| 1904 | - * @param mixed $value |
|
| 1905 | - * @param int $user_id |
|
| 1906 | - * |
|
| 1907 | - * @return bool $success |
|
| 1908 | - */ |
|
| 1909 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1910 | - |
|
| 1911 | - if( ! ( $user_id > 0 ) ){ |
|
| 1912 | - $user_id = get_current_user_id(); |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1916 | - $post_type = get_post_type( $post_id ); |
|
| 1917 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1918 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1919 | - || !get_userdata( $user_id ) |
|
| 1920 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1921 | - |
|
| 1922 | - return false; |
|
| 1923 | - } |
|
| 1924 | - |
|
| 1925 | - // check if there and existing Sensei status on this post type if not create it |
|
| 1926 | - // and get the activity ID |
|
| 1927 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 1928 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1929 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1930 | - |
|
| 1931 | - $start_function = 'user_start_'.$post_type; |
|
| 1932 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1933 | - |
|
| 1934 | - }else{ |
|
| 1935 | - |
|
| 1936 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1937 | - |
|
| 1938 | - } |
|
| 1939 | - |
|
| 1940 | - // store the data |
|
| 1941 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1942 | - |
|
| 1943 | - return $success; |
|
| 1944 | - |
|
| 1945 | - }//update_user_data |
|
| 1946 | - |
|
| 1947 | - /** |
|
| 1948 | - * Get the user data stored on the passed in post type |
|
| 1949 | - * |
|
| 1950 | - * This function gets the comment meta on the lesson or course status |
|
| 1951 | - * |
|
| 1952 | - * @since 1.7.4 |
|
| 1953 | - * |
|
| 1954 | - * @param $data_key |
|
| 1955 | - * @param $post_id |
|
| 1956 | - * @param int $user_id |
|
| 1957 | - * |
|
| 1958 | - * @return mixed $user_data_value |
|
| 1959 | - */ |
|
| 1960 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 1961 | - |
|
| 1962 | - $user_data_value = true; |
|
| 1963 | - |
|
| 1964 | - if( ! ( $user_id > 0 ) ){ |
|
| 1965 | - $user_id = get_current_user_id(); |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 1969 | - $post_type = get_post_type( $post_id ); |
|
| 1970 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 1971 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1972 | - || ! get_userdata( $user_id ) |
|
| 1973 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1974 | - |
|
| 1975 | - return false; |
|
| 1976 | - } |
|
| 1977 | - |
|
| 1978 | - // check if there and existing Sensei status on this post type if not create it |
|
| 1979 | - // and get the activity ID |
|
| 1980 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 1981 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1982 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1983 | - return false; |
|
| 1984 | - } |
|
| 1985 | - |
|
| 1986 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1987 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 1988 | - |
|
| 1989 | - return $user_data_value; |
|
| 1990 | - |
|
| 1991 | - }// end get_user_data |
|
| 1992 | - |
|
| 1993 | - /** |
|
| 1994 | - * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 1995 | - * |
|
| 1996 | - * @param int $data_key |
|
| 1997 | - * @param int $post_id |
|
| 1998 | - * @param int $user_id |
|
| 1999 | - * |
|
| 2000 | - * @return bool $deleted |
|
| 2001 | - */ |
|
| 2002 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2003 | - $deleted = true; |
|
| 1876 | + /** |
|
| 1877 | + * |
|
| 1878 | + * Alias to Woothemes_Sensei_Utils::update_user_data |
|
| 1879 | + * @since 1.7.4 |
|
| 1880 | + * |
|
| 1881 | + * @param string $data_key maximum 39 characters allowed |
|
| 1882 | + * @param int $post_id |
|
| 1883 | + * @param mixed $value |
|
| 1884 | + * @param int $user_id |
|
| 1885 | + * |
|
| 1886 | + * @return bool $success |
|
| 1887 | + */ |
|
| 1888 | + public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
| 1889 | + |
|
| 1890 | + return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
| 1891 | + |
|
| 1892 | + }// end add_user_data |
|
| 1893 | + |
|
| 1894 | + /** |
|
| 1895 | + * add user specific data to the passed in sensei post type id |
|
| 1896 | + * |
|
| 1897 | + * This function saves comment meta on the users current status. If no status is available |
|
| 1898 | + * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
| 1899 | + * |
|
| 1900 | + * @since 1.7.4 |
|
| 1901 | + * |
|
| 1902 | + * @param string $data_key maximum 39 characters allowed |
|
| 1903 | + * @param int $post_id |
|
| 1904 | + * @param mixed $value |
|
| 1905 | + * @param int $user_id |
|
| 1906 | + * |
|
| 1907 | + * @return bool $success |
|
| 1908 | + */ |
|
| 1909 | + public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
| 1910 | + |
|
| 1911 | + if( ! ( $user_id > 0 ) ){ |
|
| 1912 | + $user_id = get_current_user_id(); |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 1916 | + $post_type = get_post_type( $post_id ); |
|
| 1917 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 1918 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1919 | + || !get_userdata( $user_id ) |
|
| 1920 | + || ! in_array( $post_type, $supported_post_types ) ){ |
|
| 1921 | + |
|
| 1922 | + return false; |
|
| 1923 | + } |
|
| 1924 | + |
|
| 1925 | + // check if there and existing Sensei status on this post type if not create it |
|
| 1926 | + // and get the activity ID |
|
| 1927 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 1928 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1929 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1930 | + |
|
| 1931 | + $start_function = 'user_start_'.$post_type; |
|
| 1932 | + $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
| 1933 | + |
|
| 1934 | + }else{ |
|
| 1935 | + |
|
| 1936 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1937 | + |
|
| 1938 | + } |
|
| 1939 | + |
|
| 1940 | + // store the data |
|
| 1941 | + $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
| 1942 | + |
|
| 1943 | + return $success; |
|
| 1944 | + |
|
| 1945 | + }//update_user_data |
|
| 1946 | + |
|
| 1947 | + /** |
|
| 1948 | + * Get the user data stored on the passed in post type |
|
| 1949 | + * |
|
| 1950 | + * This function gets the comment meta on the lesson or course status |
|
| 1951 | + * |
|
| 1952 | + * @since 1.7.4 |
|
| 1953 | + * |
|
| 1954 | + * @param $data_key |
|
| 1955 | + * @param $post_id |
|
| 1956 | + * @param int $user_id |
|
| 1957 | + * |
|
| 1958 | + * @return mixed $user_data_value |
|
| 1959 | + */ |
|
| 1960 | + public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
| 1961 | + |
|
| 1962 | + $user_data_value = true; |
|
| 1963 | + |
|
| 1964 | + if( ! ( $user_id > 0 ) ){ |
|
| 1965 | + $user_id = get_current_user_id(); |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 1969 | + $post_type = get_post_type( $post_id ); |
|
| 1970 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 1971 | + || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 1972 | + || ! get_userdata( $user_id ) |
|
| 1973 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2004 | 1974 | |
| 2005 | - if( ! ( $user_id > 0 ) ){ |
|
| 2006 | - $user_id = get_current_user_id(); |
|
| 2007 | - } |
|
| 1975 | + return false; |
|
| 1976 | + } |
|
| 2008 | 1977 | |
| 2009 | - $supported_post_types = array( 'course', 'lesson' ); |
|
| 2010 | - $post_type = get_post_type( $post_id ); |
|
| 2011 | - if( empty( $post_id ) || empty( $data_key ) |
|
| 2012 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2013 | - || ! get_userdata( $user_id ) |
|
| 2014 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
| 1978 | + // check if there and existing Sensei status on this post type if not create it |
|
| 1979 | + // and get the activity ID |
|
| 1980 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 1981 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 1982 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 1983 | + return false; |
|
| 1984 | + } |
|
| 2015 | 1985 | |
| 2016 | - return false; |
|
| 2017 | - } |
|
| 1986 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 1987 | + $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
| 1988 | + |
|
| 1989 | + return $user_data_value; |
|
| 1990 | + |
|
| 1991 | + }// end get_user_data |
|
| 1992 | + |
|
| 1993 | + /** |
|
| 1994 | + * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
| 1995 | + * |
|
| 1996 | + * @param int $data_key |
|
| 1997 | + * @param int $post_id |
|
| 1998 | + * @param int $user_id |
|
| 1999 | + * |
|
| 2000 | + * @return bool $deleted |
|
| 2001 | + */ |
|
| 2002 | + public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
| 2003 | + $deleted = true; |
|
| 2004 | + |
|
| 2005 | + if( ! ( $user_id > 0 ) ){ |
|
| 2006 | + $user_id = get_current_user_id(); |
|
| 2007 | + } |
|
| 2008 | + |
|
| 2009 | + $supported_post_types = array( 'course', 'lesson' ); |
|
| 2010 | + $post_type = get_post_type( $post_id ); |
|
| 2011 | + if( empty( $post_id ) || empty( $data_key ) |
|
| 2012 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
| 2013 | + || ! get_userdata( $user_id ) |
|
| 2014 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
| 2015 | + |
|
| 2016 | + return false; |
|
| 2017 | + } |
|
| 2018 | 2018 | |
| 2019 | - // check if there and existing Sensei status on this post type if not create it |
|
| 2020 | - // and get the activity ID |
|
| 2021 | - $status_function = 'user_'.$post_type.'_status'; |
|
| 2022 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2023 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2024 | - return false; |
|
| 2025 | - } |
|
| 2019 | + // check if there and existing Sensei status on this post type if not create it |
|
| 2020 | + // and get the activity ID |
|
| 2021 | + $status_function = 'user_'.$post_type.'_status'; |
|
| 2022 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
| 2023 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
| 2024 | + return false; |
|
| 2025 | + } |
|
| 2026 | 2026 | |
| 2027 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2028 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2027 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
| 2028 | + $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
| 2029 | 2029 | |
| 2030 | - return $deleted; |
|
| 2030 | + return $deleted; |
|
| 2031 | 2031 | |
| 2032 | - }// end delete_user_data |
|
| 2032 | + }// end delete_user_data |
|
| 2033 | 2033 | |
| 2034 | 2034 | |
| 2035 | - /** |
|
| 2036 | - * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2037 | - * |
|
| 2038 | - * @since 1.8.0 |
|
| 2039 | - * |
|
| 2040 | - * @param string $selected_value |
|
| 2041 | - * @param $options{ |
|
| 2042 | - * @type string $value the value saved in the database |
|
| 2043 | - * @type string $option what the user will see in the list of items |
|
| 2044 | - * } |
|
| 2045 | - * @param array $attributes{ |
|
| 2046 | - * @type string $attribute type such name or id etc. |
|
| 2047 | - * @type string $value |
|
| 2048 | - * } |
|
| 2049 | - * @param bool $enable_none_option |
|
| 2050 | - * |
|
| 2051 | - * @return string $drop_down_element |
|
| 2052 | - */ |
|
| 2053 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2035 | + /** |
|
| 2036 | + * The function creates a drop down. Never write up a Sensei select statement again. |
|
| 2037 | + * |
|
| 2038 | + * @since 1.8.0 |
|
| 2039 | + * |
|
| 2040 | + * @param string $selected_value |
|
| 2041 | + * @param $options{ |
|
| 2042 | + * @type string $value the value saved in the database |
|
| 2043 | + * @type string $option what the user will see in the list of items |
|
| 2044 | + * } |
|
| 2045 | + * @param array $attributes{ |
|
| 2046 | + * @type string $attribute type such name or id etc. |
|
| 2047 | + * @type string $value |
|
| 2048 | + * } |
|
| 2049 | + * @param bool $enable_none_option |
|
| 2050 | + * |
|
| 2051 | + * @return string $drop_down_element |
|
| 2052 | + */ |
|
| 2053 | + public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
| 2054 | 2054 | |
| 2055 | - $drop_down_element = ''; |
|
| 2055 | + $drop_down_element = ''; |
|
| 2056 | 2056 | |
| 2057 | - // setup the basic attributes |
|
| 2058 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2057 | + // setup the basic attributes |
|
| 2058 | + if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
| 2059 | 2059 | |
| 2060 | - $attributes['name'] = 'sensei-options'; |
|
| 2060 | + $attributes['name'] = 'sensei-options'; |
|
| 2061 | 2061 | |
| 2062 | - } |
|
| 2062 | + } |
|
| 2063 | 2063 | |
| 2064 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2064 | + if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
| 2065 | 2065 | |
| 2066 | - $attributes['id'] = 'sensei-options'; |
|
| 2066 | + $attributes['id'] = 'sensei-options'; |
|
| 2067 | 2067 | |
| 2068 | - } |
|
| 2068 | + } |
|
| 2069 | 2069 | |
| 2070 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2070 | + if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
| 2071 | 2071 | |
| 2072 | - $attributes['class'] ='chosen_select widefat'; |
|
| 2072 | + $attributes['class'] ='chosen_select widefat'; |
|
| 2073 | 2073 | |
| 2074 | - } |
|
| 2074 | + } |
|
| 2075 | 2075 | |
| 2076 | - // create element attributes |
|
| 2077 | - $combined_attributes = ''; |
|
| 2078 | - foreach( $attributes as $attribute => $value ){ |
|
| 2076 | + // create element attributes |
|
| 2077 | + $combined_attributes = ''; |
|
| 2078 | + foreach( $attributes as $attribute => $value ){ |
|
| 2079 | 2079 | |
| 2080 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2080 | + $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
| 2081 | 2081 | |
| 2082 | - }// end for each |
|
| 2082 | + }// end for each |
|
| 2083 | 2083 | |
| 2084 | 2084 | |
| 2085 | - // create the select element |
|
| 2086 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2085 | + // create the select element |
|
| 2086 | + $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
| 2087 | 2087 | |
| 2088 | - // show the none option if the client requested |
|
| 2089 | - if( $enable_none_option ) { |
|
| 2090 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2091 | - } |
|
| 2088 | + // show the none option if the client requested |
|
| 2089 | + if( $enable_none_option ) { |
|
| 2090 | + $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
| 2091 | + } |
|
| 2092 | 2092 | |
| 2093 | - if ( count( $options ) > 0 ) { |
|
| 2093 | + if ( count( $options ) > 0 ) { |
|
| 2094 | 2094 | |
| 2095 | - foreach ($options as $value => $option ){ |
|
| 2095 | + foreach ($options as $value => $option ){ |
|
| 2096 | 2096 | |
| 2097 | - $element = ''; |
|
| 2098 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2099 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2100 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2097 | + $element = ''; |
|
| 2098 | + $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
| 2099 | + $element .= selected( $value, $selected_value, false ) . '>'; |
|
| 2100 | + $element .= esc_html( $option ) . '</option>' . "\n"; |
|
| 2101 | 2101 | |
| 2102 | - // add the element to the select html |
|
| 2103 | - $drop_down_element.= $element; |
|
| 2104 | - } // End For Loop |
|
| 2102 | + // add the element to the select html |
|
| 2103 | + $drop_down_element.= $element; |
|
| 2104 | + } // End For Loop |
|
| 2105 | 2105 | |
| 2106 | - } // End If Statement |
|
| 2106 | + } // End If Statement |
|
| 2107 | 2107 | |
| 2108 | - $drop_down_element .= '</select>' . "\n"; |
|
| 2108 | + $drop_down_element .= '</select>' . "\n"; |
|
| 2109 | 2109 | |
| 2110 | - return $drop_down_element; |
|
| 2110 | + return $drop_down_element; |
|
| 2111 | 2111 | |
| 2112 | - }// generate_drop_down |
|
| 2112 | + }// generate_drop_down |
|
| 2113 | 2113 | |
| 2114 | - /** |
|
| 2115 | - * Wrapper for the default php round() function. |
|
| 2116 | - * This allows us to give more control to a user on how they can round Sensei |
|
| 2117 | - * decimals passed through this function. |
|
| 2118 | - * |
|
| 2119 | - * @since 1.8.5 |
|
| 2120 | - * |
|
| 2121 | - * @param double $val |
|
| 2122 | - * @param int $precision |
|
| 2123 | - * @param $mode |
|
| 2124 | - * @param string $context |
|
| 2125 | - * |
|
| 2126 | - * @return double $val |
|
| 2127 | - */ |
|
| 2128 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2114 | + /** |
|
| 2115 | + * Wrapper for the default php round() function. |
|
| 2116 | + * This allows us to give more control to a user on how they can round Sensei |
|
| 2117 | + * decimals passed through this function. |
|
| 2118 | + * |
|
| 2119 | + * @since 1.8.5 |
|
| 2120 | + * |
|
| 2121 | + * @param double $val |
|
| 2122 | + * @param int $precision |
|
| 2123 | + * @param $mode |
|
| 2124 | + * @param string $context |
|
| 2125 | + * |
|
| 2126 | + * @return double $val |
|
| 2127 | + */ |
|
| 2128 | + public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
| 2129 | 2129 | |
| 2130 | - /**å |
|
| 2130 | + /**å |
|
| 2131 | 2131 | * Change the precision for the Sensei_Utils::round function. |
| 2132 | 2132 | * the precision given will be passed into the php round function |
| 2133 | 2133 | * @since 1.8.5 |
| 2134 | 2134 | */ |
| 2135 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * Change the mode for the Sensei_Utils::round function. |
|
| 2139 | - * the mode given will be passed into the php round function |
|
| 2140 | - * |
|
| 2141 | - * This applies only to PHP version 5.3.0 and greater |
|
| 2142 | - * |
|
| 2143 | - * @since 1.8.5 |
|
| 2144 | - */ |
|
| 2145 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2135 | + $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * Change the mode for the Sensei_Utils::round function. |
|
| 2139 | + * the mode given will be passed into the php round function |
|
| 2140 | + * |
|
| 2141 | + * This applies only to PHP version 5.3.0 and greater |
|
| 2142 | + * |
|
| 2143 | + * @since 1.8.5 |
|
| 2144 | + */ |
|
| 2145 | + $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
| 2146 | 2146 | |
| 2147 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2147 | + if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
| 2148 | 2148 | |
| 2149 | - return round( $val, $precision, $mode ); |
|
| 2149 | + return round( $val, $precision, $mode ); |
|
| 2150 | 2150 | |
| 2151 | - }else{ |
|
| 2151 | + }else{ |
|
| 2152 | 2152 | |
| 2153 | - return round( $val, $precision ); |
|
| 2153 | + return round( $val, $precision ); |
|
| 2154 | 2154 | |
| 2155 | - } |
|
| 2155 | + } |
|
| 2156 | 2156 | |
| 2157 | - } |
|
| 2157 | + } |
|
| 2158 | 2158 | |
| 2159 | - /** |
|
| 2160 | - * Returns the current url with all the query vars |
|
| 2161 | - * |
|
| 2162 | - * @since 1.9.0 |
|
| 2163 | - * @return string $url |
|
| 2164 | - */ |
|
| 2165 | - public static function get_current_url(){ |
|
| 2159 | + /** |
|
| 2160 | + * Returns the current url with all the query vars |
|
| 2161 | + * |
|
| 2162 | + * @since 1.9.0 |
|
| 2163 | + * @return string $url |
|
| 2164 | + */ |
|
| 2165 | + public static function get_current_url(){ |
|
| 2166 | 2166 | |
| 2167 | - global $wp; |
|
| 2168 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2169 | - if ( isset( $_GET ) ) { |
|
| 2167 | + global $wp; |
|
| 2168 | + $current_url = trailingslashit( home_url( $wp->request ) ); |
|
| 2169 | + if ( isset( $_GET ) ) { |
|
| 2170 | 2170 | |
| 2171 | - foreach ($_GET as $param => $val ) { |
|
| 2171 | + foreach ($_GET as $param => $val ) { |
|
| 2172 | 2172 | |
| 2173 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2173 | + $current_url = add_query_arg( $param, $val , $current_url ); |
|
| 2174 | 2174 | |
| 2175 | - } |
|
| 2176 | - } |
|
| 2175 | + } |
|
| 2176 | + } |
|
| 2177 | 2177 | |
| 2178 | - return $current_url; |
|
| 2179 | - } |
|
| 2178 | + return $current_url; |
|
| 2179 | + } |
|
| 2180 | 2180 | |
| 2181 | - /** |
|
| 2182 | - * Restore the global WP_Query |
|
| 2183 | - * |
|
| 2184 | - * @since 1.9.0 |
|
| 2185 | - */ |
|
| 2186 | - public static function restore_wp_query() { |
|
| 2181 | + /** |
|
| 2182 | + * Restore the global WP_Query |
|
| 2183 | + * |
|
| 2184 | + * @since 1.9.0 |
|
| 2185 | + */ |
|
| 2186 | + public static function restore_wp_query() { |
|
| 2187 | 2187 | |
| 2188 | - wp_reset_query(); |
|
| 2188 | + wp_reset_query(); |
|
| 2189 | 2189 | |
| 2190 | - } |
|
| 2190 | + } |
|
| 2191 | 2191 | |
| 2192 | - /** |
|
| 2193 | - * Merge two arrays in a zip like fashion. |
|
| 2194 | - * If one array is longer than the other the elements will be apended |
|
| 2195 | - * to the end of the resulting array. |
|
| 2196 | - * |
|
| 2197 | - * @since 1.9.0 |
|
| 2198 | - * |
|
| 2199 | - * @param array $array_a |
|
| 2200 | - * @param array $array_b |
|
| 2201 | - * @return array $merged_array |
|
| 2202 | - */ |
|
| 2203 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2192 | + /** |
|
| 2193 | + * Merge two arrays in a zip like fashion. |
|
| 2194 | + * If one array is longer than the other the elements will be apended |
|
| 2195 | + * to the end of the resulting array. |
|
| 2196 | + * |
|
| 2197 | + * @since 1.9.0 |
|
| 2198 | + * |
|
| 2199 | + * @param array $array_a |
|
| 2200 | + * @param array $array_b |
|
| 2201 | + * @return array $merged_array |
|
| 2202 | + */ |
|
| 2203 | + public static function array_zip_merge( $array_a, $array_b ){ |
|
| 2204 | 2204 | |
| 2205 | - if( ! is_array( $array_a ) || ! is_array( $array_b ) ){ |
|
| 2206 | - trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2207 | - } |
|
| 2205 | + if( ! is_array( $array_a ) || ! is_array( $array_b ) ){ |
|
| 2206 | + trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
| 2207 | + } |
|
| 2208 | 2208 | |
| 2209 | - $merged_array = array(); |
|
| 2210 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2209 | + $merged_array = array(); |
|
| 2210 | + $total_elements = count( $array_a ) + count( $array_b ); |
|
| 2211 | 2211 | |
| 2212 | - // Zip arrays |
|
| 2213 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2212 | + // Zip arrays |
|
| 2213 | + for ( $i = 0; $i < $total_elements; $i++) { |
|
| 2214 | 2214 | |
| 2215 | - // if has an element at current index push a on top |
|
| 2216 | - if( isset( $array_a[ $i ] ) ){ |
|
| 2217 | - $merged_array[] = $array_a[ $i ] ; |
|
| 2218 | - } |
|
| 2215 | + // if has an element at current index push a on top |
|
| 2216 | + if( isset( $array_a[ $i ] ) ){ |
|
| 2217 | + $merged_array[] = $array_a[ $i ] ; |
|
| 2218 | + } |
|
| 2219 | 2219 | |
| 2220 | - // next if $array_b has an element at current index push a on top of the element |
|
| 2221 | - // from a if there was one, if not the element before that. |
|
| 2222 | - if( isset( $array_b[ $i ] ) ){ |
|
| 2223 | - $merged_array[] = $array_b[ $i ] ; |
|
| 2224 | - } |
|
| 2220 | + // next if $array_b has an element at current index push a on top of the element |
|
| 2221 | + // from a if there was one, if not the element before that. |
|
| 2222 | + if( isset( $array_b[ $i ] ) ){ |
|
| 2223 | + $merged_array[] = $array_b[ $i ] ; |
|
| 2224 | + } |
|
| 2225 | 2225 | |
| 2226 | - } |
|
| 2226 | + } |
|
| 2227 | 2227 | |
| 2228 | - return $merged_array; |
|
| 2229 | - } |
|
| 2228 | + return $merged_array; |
|
| 2229 | + } |
|
| 2230 | 2230 | |
| 2231 | 2231 | } // End Class |
| 2232 | 2232 | |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | 'order' => $order, |
| 160 | 160 | ); |
| 161 | 161 | |
| 162 | - // Handle search |
|
| 163 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 164 | - $args['search'] = esc_html( $_GET['s'] ); |
|
| 165 | - } |
|
| 162 | + // Handle search |
|
| 163 | + if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 164 | + $args['search'] = esc_html( $_GET['s'] ); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | switch ( $this->type ) { |
| 168 | 168 | case 'courses': |
@@ -219,10 +219,10 @@ discard block |
||
| 219 | 219 | ); |
| 220 | 220 | |
| 221 | 221 | |
| 222 | - // Handle search |
|
| 223 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 224 | - $args['search'] = esc_html( $_GET['s'] ); |
|
| 225 | - } |
|
| 222 | + // Handle search |
|
| 223 | + if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 224 | + $args['search'] = esc_html( $_GET['s'] ); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | 227 | |
| 228 | 228 | // Start the csv with the column headings |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * Generates the overall array for a single item in the display |
| 261 | 261 | * @since 1.7.0 |
| 262 | 262 | * @param object $item The current item |
| 263 | - * @return array $column_data; |
|
| 263 | + * @return array $column_data; |
|
| 264 | 264 | */ |
| 265 | 265 | protected function get_row_data( $item ) { |
| 266 | 266 | |
@@ -296,10 +296,10 @@ discard block |
||
| 296 | 296 | $percent_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_percentage', $grade_args, $item ), true ) ); |
| 297 | 297 | $percent_total = Sensei_Grading::get_course_users_grades_sum( $item->ID ); |
| 298 | 298 | |
| 299 | - $course_average_percent = 0; |
|
| 300 | - if( $percent_count > 0 && $percent_total > 0 ){ |
|
| 301 | - $course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) ); |
|
| 302 | - } |
|
| 299 | + $course_average_percent = 0; |
|
| 300 | + if( $percent_count > 0 && $percent_total > 0 ){ |
|
| 301 | + $course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) ); |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | 304 | |
| 305 | 305 | // Output course data |
@@ -355,12 +355,12 @@ discard block |
||
| 355 | 355 | $grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true )); |
| 356 | 356 | $grade_total = Sensei_Grading::get_lessons_users_grades_sum( $item->ID ); |
| 357 | 357 | |
| 358 | - $lesson_average_grade = 0; |
|
| 359 | - if( $grade_total > 0 && $grade_count > 0 ){ |
|
| 360 | - $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
| 361 | - } |
|
| 358 | + $lesson_average_grade = 0; |
|
| 359 | + if( $grade_total > 0 && $grade_count > 0 ){ |
|
| 360 | + $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | - } |
|
| 363 | + } |
|
| 364 | 364 | // Output lesson data |
| 365 | 365 | if ( $this->csv_output ) { |
| 366 | 366 | $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
@@ -417,15 +417,15 @@ discard block |
||
| 417 | 417 | $grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_lesson_grades', $grade_args, $item ), true )); |
| 418 | 418 | $grade_total = Sensei_Grading::get_user_graded_lessons_sum( $item->ID ); |
| 419 | 419 | |
| 420 | - $user_average_grade = 0; |
|
| 421 | - if( $grade_total > 0 && $grade_count > 0 ){ |
|
| 422 | - $user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
| 423 | - } |
|
| 420 | + $user_average_grade = 0; |
|
| 421 | + if( $grade_total > 0 && $grade_count > 0 ){ |
|
| 422 | + $user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | 425 | // Output the users data |
| 426 | 426 | if ( $this->csv_output ) { |
| 427 | - $user_name = Sensei_Learner::get_full_name( $item->ID ); |
|
| 428 | - } |
|
| 427 | + $user_name = Sensei_Learner::get_full_name( $item->ID ); |
|
| 428 | + } |
|
| 429 | 429 | else { |
| 430 | 430 | $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) ); |
| 431 | 431 | $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>'; |
@@ -519,17 +519,17 @@ discard block |
||
| 519 | 519 | // This stops the full meta data of each user being loaded |
| 520 | 520 | $args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' ); |
| 521 | 521 | |
| 522 | - /** |
|
| 523 | - * Filter the WP_User_Query arguments |
|
| 524 | - * @since 1.6.0 |
|
| 525 | - * @param $args |
|
| 526 | - */ |
|
| 527 | - $args = apply_filters( 'sensei_analysis_overview_filter_users', $args ); |
|
| 522 | + /** |
|
| 523 | + * Filter the WP_User_Query arguments |
|
| 524 | + * @since 1.6.0 |
|
| 525 | + * @param $args |
|
| 526 | + */ |
|
| 527 | + $args = apply_filters( 'sensei_analysis_overview_filter_users', $args ); |
|
| 528 | 528 | $wp_user_search = new WP_User_Query( $args ); |
| 529 | - $learners = $wp_user_search->get_results(); |
|
| 529 | + $learners = $wp_user_search->get_results(); |
|
| 530 | 530 | $this->total_items = $wp_user_search->get_total(); |
| 531 | 531 | |
| 532 | - return $learners; |
|
| 532 | + return $learners; |
|
| 533 | 533 | |
| 534 | 534 | } // End get_learners() |
| 535 | 535 | |
@@ -546,15 +546,15 @@ discard block |
||
| 546 | 546 | $total_courses = Sensei()->course->course_count( array('publish', 'private') ); |
| 547 | 547 | $total_lessons = Sensei()->lesson->lesson_count( array('publish', 'private') ); |
| 548 | 548 | |
| 549 | - /** |
|
| 550 | - * filter the analysis tot grades query args |
|
| 551 | - */ |
|
| 549 | + /** |
|
| 550 | + * filter the analysis tot grades query args |
|
| 551 | + */ |
|
| 552 | 552 | $grade_args = apply_filters( 'sensei_analysis_total_quiz_grades', array( |
| 553 | 553 | 'type' => 'sensei_lesson_status', |
| 554 | 554 | 'status' => 'any', |
| 555 | 555 | |
| 556 | - 'meta_key' => 'grade' |
|
| 557 | - )); |
|
| 556 | + 'meta_key' => 'grade' |
|
| 557 | + )); |
|
| 558 | 558 | |
| 559 | 559 | $total_grade_count = Sensei_Grading::get_graded_lessons_count(); |
| 560 | 560 | $total_grade_total = Sensei_Grading::get_graded_lessons_sum(); |
@@ -1,26 +1,26 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * The Template for displaying course archives, including the course page template. |
|
| 4 | - * |
|
| 5 | - * Override this template by copying it to yourtheme/sensei/archive-course.php |
|
| 6 | - * |
|
| 7 | - * @author Automattic |
|
| 8 | - * @package Sensei |
|
| 9 | - * @category Templates |
|
| 10 | - * @version 1.9.0 |
|
| 11 | - */ |
|
| 3 | + * The Template for displaying course archives, including the course page template. |
|
| 4 | + * |
|
| 5 | + * Override this template by copying it to yourtheme/sensei/archive-course.php |
|
| 6 | + * |
|
| 7 | + * @author Automattic |
|
| 8 | + * @package Sensei |
|
| 9 | + * @category Templates |
|
| 10 | + * @version 1.9.0 |
|
| 11 | + */ |
|
| 12 | 12 | ?> |
| 13 | 13 | |
| 14 | 14 | <?php get_sensei_header(); ?> |
| 15 | 15 | |
| 16 | 16 | <?php |
| 17 | 17 | /** |
| 18 | - * This hook fire inside learner-profile.php before the content |
|
| 19 | - * |
|
| 20 | - * @since 1.9.0 |
|
| 21 | - * |
|
| 22 | - * @hooked Sensei_Course_Results::deprecate_sensei_course_results_content_hook() - 20 |
|
| 23 | - */ |
|
| 18 | + * This hook fire inside learner-profile.php before the content |
|
| 19 | + * |
|
| 20 | + * @since 1.9.0 |
|
| 21 | + * |
|
| 22 | + * @hooked Sensei_Course_Results::deprecate_sensei_course_results_content_hook() - 20 |
|
| 23 | + */ |
|
| 24 | 24 | do_action( 'sensei_course_results_content_before' ); |
| 25 | 25 | ?> |
| 26 | 26 | |
@@ -34,16 +34,16 @@ discard block |
||
| 34 | 34 | <section class="entry fix"> |
| 35 | 35 | |
| 36 | 36 | <?php |
| 37 | - /** |
|
| 38 | - * This hook fire inside learner-profile.php inside directly before the content |
|
| 39 | - * |
|
| 40 | - * @since 1.9.0 |
|
| 41 | - * |
|
| 42 | - * @param integer $course_id |
|
| 43 | - * |
|
| 44 | - */ |
|
| 45 | - do_action( 'sensei_course_results_content_inside_before', $course->ID ); |
|
| 46 | - ?> |
|
| 37 | + /** |
|
| 38 | + * This hook fire inside learner-profile.php inside directly before the content |
|
| 39 | + * |
|
| 40 | + * @since 1.9.0 |
|
| 41 | + * |
|
| 42 | + * @param integer $course_id |
|
| 43 | + * |
|
| 44 | + */ |
|
| 45 | + do_action( 'sensei_course_results_content_inside_before', $course->ID ); |
|
| 46 | + ?> |
|
| 47 | 47 | |
| 48 | 48 | <header> |
| 49 | 49 | |
@@ -56,44 +56,44 @@ discard block |
||
| 56 | 56 | <?php if ( is_user_logged_in() ):?> |
| 57 | 57 | |
| 58 | 58 | <?php |
| 59 | - /** |
|
| 60 | - * This hook fire inside learner-profile.php inside directly before the content |
|
| 61 | - * |
|
| 62 | - * @since 1.9.0 |
|
| 63 | - * |
|
| 64 | - * @param integer $course_id |
|
| 65 | - * |
|
| 66 | - * @hooked Sensei_Course_Results::course_info() - 20 |
|
| 67 | - */ |
|
| 68 | - do_action( 'sensei_course_results_content_inside_before_lessons', $course->ID ); |
|
| 69 | - ?> |
|
| 59 | + /** |
|
| 60 | + * This hook fire inside learner-profile.php inside directly before the content |
|
| 61 | + * |
|
| 62 | + * @since 1.9.0 |
|
| 63 | + * |
|
| 64 | + * @param integer $course_id |
|
| 65 | + * |
|
| 66 | + * @hooked Sensei_Course_Results::course_info() - 20 |
|
| 67 | + */ |
|
| 68 | + do_action( 'sensei_course_results_content_inside_before_lessons', $course->ID ); |
|
| 69 | + ?> |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | 72 | <section class="course-results-lessons"> |
| 73 | 73 | <?php |
| 74 | - $started_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 75 | - if( $started_course ) { |
|
| 74 | + $started_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 75 | + if( $started_course ) { |
|
| 76 | 76 | |
| 77 | - sensei_the_course_results_lessons(); |
|
| 77 | + sensei_the_course_results_lessons(); |
|
| 78 | 78 | |
| 79 | - } |
|
| 80 | - ?> |
|
| 79 | + } |
|
| 80 | + ?> |
|
| 81 | 81 | </section> |
| 82 | 82 | |
| 83 | 83 | <?php endif; ?> |
| 84 | 84 | |
| 85 | 85 | <?php |
| 86 | - /** |
|
| 87 | - * This hook fire inside learner-profile.php inside directly after the content |
|
| 88 | - * |
|
| 89 | - * @since 1.9.0 |
|
| 90 | - * |
|
| 91 | - * @param integer $course_id |
|
| 92 | - * |
|
| 93 | - * @hooked Sensei()->course_results->course_info - 20 |
|
| 94 | - */ |
|
| 95 | - do_action( 'sensei_course_results_content_inside_after', $course->ID ); |
|
| 96 | - ?> |
|
| 86 | + /** |
|
| 87 | + * This hook fire inside learner-profile.php inside directly after the content |
|
| 88 | + * |
|
| 89 | + * @since 1.9.0 |
|
| 90 | + * |
|
| 91 | + * @param integer $course_id |
|
| 92 | + * |
|
| 93 | + * @hooked Sensei()->course_results->course_info - 20 |
|
| 94 | + */ |
|
| 95 | + do_action( 'sensei_course_results_content_inside_after', $course->ID ); |
|
| 96 | + ?> |
|
| 97 | 97 | |
| 98 | 98 | </section> |
| 99 | 99 | |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | <?php |
| 103 | 103 | /** |
| 104 | - * This hook fire inside course-results.php before the content |
|
| 105 | - * |
|
| 106 | - * @since 1.9.0 |
|
| 107 | - * |
|
| 108 | - */ |
|
| 104 | + * This hook fire inside course-results.php before the content |
|
| 105 | + * |
|
| 106 | + * @since 1.9.0 |
|
| 107 | + * |
|
| 108 | + */ |
|
| 109 | 109 | do_action( 'sensei_course_results_content_after' ); |
| 110 | 110 | ?> |
| 111 | 111 | |
@@ -1,42 +1,42 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Class Sensei__S |
|
| 4 | - * |
|
| 5 | - * Responsible for wrapping for the underscores theme |
|
| 6 | - * with the correct markup |
|
| 7 | - * |
|
| 8 | - * |
|
| 9 | - * @package Views |
|
| 10 | - * @subpackage Theme-Integration |
|
| 11 | - * @author Automattic |
|
| 12 | - * |
|
| 13 | - * @since 1.9.0 |
|
| 3 | + * Class Sensei__S |
|
| 4 | + * |
|
| 5 | + * Responsible for wrapping for the underscores theme |
|
| 6 | + * with the correct markup |
|
| 7 | + * |
|
| 8 | + * |
|
| 9 | + * @package Views |
|
| 10 | + * @subpackage Theme-Integration |
|
| 11 | + * @author Automattic |
|
| 12 | + * |
|
| 13 | + * @since 1.9.0 |
|
| 14 | 14 | */ |
| 15 | 15 | Class Sensei__S { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Output opening wrappers |
|
| 19 | - * @since 1.9.0 |
|
| 20 | - */ |
|
| 21 | - public function wrapper_start(){ ?> |
|
| 17 | + /** |
|
| 18 | + * Output opening wrappers |
|
| 19 | + * @since 1.9.0 |
|
| 20 | + */ |
|
| 21 | + public function wrapper_start(){ ?> |
|
| 22 | 22 | <div id="primary" class="content-area"> |
| 23 | 23 | <main id="main" class="site-main" role="main"> |
| 24 | 24 | |
| 25 | 25 | <?php } |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Output closing wrappers |
|
| 29 | - * |
|
| 30 | - * @since 1.9.0 |
|
| 31 | - */ |
|
| 32 | - public function wrapper_end(){ ?> |
|
| 27 | + /** |
|
| 28 | + * Output closing wrappers |
|
| 29 | + * |
|
| 30 | + * @since 1.9.0 |
|
| 31 | + */ |
|
| 32 | + public function wrapper_end(){ ?> |
|
| 33 | 33 | |
| 34 | 34 | </main> <!-- main-site --> |
| 35 | 35 | </div> <!-- content-area --> |
| 36 | 36 | |
| 37 | 37 | <?php |
| 38 | 38 | |
| 39 | - get_sidebar(); |
|
| 39 | + get_sidebar(); |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | } // end class |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | public function __construct () { |
| 18 | 18 | |
| 19 | - //register admin styles |
|
| 19 | + //register admin styles |
|
| 20 | 20 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_global' ) ); |
| 21 | 21 | |
| 22 | - //register admin scripts |
|
| 23 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) ); |
|
| 22 | + //register admin scripts |
|
| 23 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) ); |
|
| 24 | 24 | |
| 25 | 25 | add_action( 'admin_print_styles', array( $this, 'admin_notices_styles' ) ); |
| 26 | 26 | add_action( 'settings_before_form', array( $this, 'install_pages_output' ) ); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | add_action( 'admin_head', array( $this, 'admin_menu_highlight' ) ); |
| 30 | 30 | add_action( 'admin_init', array( $this, 'page_redirect' ) ); |
| 31 | 31 | add_action( 'admin_init', array( $this, 'sensei_add_custom_menu_items' ) ); |
| 32 | - add_action( 'admin_init', array( __CLASS__, 'install_pages' )); |
|
| 32 | + add_action( 'admin_init', array( __CLASS__, 'install_pages' )); |
|
| 33 | 33 | |
| 34 | 34 | // Duplicate lesson & courses |
| 35 | 35 | add_filter( 'post_row_actions', array( $this, 'duplicate_action_link' ), 10, 2 ); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | if( $menu_cap ) { |
| 82 | 82 | $menu[] = array( '', 'read', 'separator-sensei', '', 'wp-menu-separator sensei' ); |
| 83 | - add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' ); |
|
| 83 | + add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | add_submenu_page( 'edit.php?post_type=course', __( 'Order Courses', 'woothemes-sensei' ), __( 'Order Courses', 'woothemes-sensei' ), 'manage_sensei', 'course-order', array( $this, 'course_order_screen' ) ); |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | $screen = get_current_screen(); |
| 130 | 130 | |
| 131 | - if( empty( $screen ) ){ |
|
| 132 | - return; |
|
| 133 | - } |
|
| 131 | + if( empty( $screen ) ){ |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | if ( $screen->base == 'post' && $post_type == 'course' ) { |
| 136 | 136 | |
@@ -141,14 +141,14 @@ discard block |
||
| 141 | 141 | $submenu_file = 'edit-tags.php?taxonomy=course-category&post_type=course'; |
| 142 | 142 | $parent_file = 'edit.php?post_type=course'; |
| 143 | 143 | |
| 144 | - } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) { |
|
| 144 | + } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) { |
|
| 145 | 145 | |
| 146 | - $submenu_file = 'edit-tags.php?taxonomy=module'; |
|
| 147 | - $parent_file = 'edit.php?post_type=course'; |
|
| 146 | + $submenu_file = 'edit-tags.php?taxonomy=module'; |
|
| 147 | + $parent_file = 'edit.php?post_type=course'; |
|
| 148 | 148 | |
| 149 | 149 | } elseif ( in_array( $screen->id, array( 'sensei_message', 'edit-sensei_message' ) ) ) { |
| 150 | 150 | |
| 151 | - $submenu_file = 'edit.php?post_type=sensei_message'; |
|
| 151 | + $submenu_file = 'edit.php?post_type=sensei_message'; |
|
| 152 | 152 | $parent_file = 'sensei'; |
| 153 | 153 | |
| 154 | 154 | } |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | function install_pages_output() { |
| 178 | 178 | |
| 179 | - if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
| 179 | + if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
| 180 | 180 | |
| 181 | - ?> |
|
| 181 | + ?> |
|
| 182 | 182 | <div id="message" class="updated sensei-message sensei-connect"> |
| 183 | 183 | <p><?php _e( '<strong>Congratulations!</strong> – Sensei has been installed and set up.', 'woothemes-sensei' ); ?></p> |
| 184 | 184 | <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/sensei/" data-text="A premium Learning Management plugin for #WordPress that helps you create courses. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="Sensei">Tweet</a> |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | </div> |
| 187 | 187 | <?php |
| 188 | 188 | |
| 189 | - } |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | 191 | } // End install_pages_output() |
| 192 | 192 | |
@@ -205,25 +205,25 @@ discard block |
||
| 205 | 205 | function create_page( $slug, $page_title = '', $page_content = '', $post_parent = 0 ) { |
| 206 | 206 | global $wpdb; |
| 207 | 207 | |
| 208 | - $page_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) ); |
|
| 208 | + $page_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) ); |
|
| 209 | 209 | if ( $page_id ) : |
| 210 | 210 | return $page_id; |
| 211 | 211 | endif; |
| 212 | 212 | |
| 213 | 213 | $page_data = array( |
| 214 | - 'post_status' => 'publish', |
|
| 215 | - 'post_type' => 'page', |
|
| 216 | - 'post_author' => 1, |
|
| 217 | - 'post_name' => $slug, |
|
| 218 | - 'post_title' => $page_title, |
|
| 219 | - 'post_content' => $page_content, |
|
| 220 | - 'post_parent' => $post_parent, |
|
| 221 | - 'comment_status' => 'closed' |
|
| 222 | - ); |
|
| 214 | + 'post_status' => 'publish', |
|
| 215 | + 'post_type' => 'page', |
|
| 216 | + 'post_author' => 1, |
|
| 217 | + 'post_name' => $slug, |
|
| 218 | + 'post_title' => $page_title, |
|
| 219 | + 'post_content' => $page_content, |
|
| 220 | + 'post_parent' => $post_parent, |
|
| 221 | + 'comment_status' => 'closed' |
|
| 222 | + ); |
|
| 223 | 223 | |
| 224 | - $page_id = wp_insert_post( $page_data ); |
|
| 224 | + $page_id = wp_insert_post( $page_data ); |
|
| 225 | 225 | |
| 226 | - return $page_id; |
|
| 226 | + return $page_id; |
|
| 227 | 227 | |
| 228 | 228 | } // End create_page() |
| 229 | 229 | |
@@ -237,12 +237,12 @@ discard block |
||
| 237 | 237 | function create_pages() { |
| 238 | 238 | |
| 239 | 239 | // Courses page |
| 240 | - $new_course_page_id = $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), __('Courses', 'woothemes-sensei'), '' ); |
|
| 241 | - Sensei()->settings->set( 'course_page', $new_course_page_id ); |
|
| 240 | + $new_course_page_id = $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), __('Courses', 'woothemes-sensei'), '' ); |
|
| 241 | + Sensei()->settings->set( 'course_page', $new_course_page_id ); |
|
| 242 | 242 | |
| 243 | - // User Dashboard page |
|
| 244 | - $new_my_course_page_id = $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), __('My Courses', 'woothemes-sensei'), '[sensei_user_courses]' ); |
|
| 245 | - Sensei()->settings->set( 'my_course_page',$new_my_course_page_id ); |
|
| 243 | + // User Dashboard page |
|
| 244 | + $new_my_course_page_id = $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), __('My Courses', 'woothemes-sensei'), '[sensei_user_courses]' ); |
|
| 245 | + Sensei()->settings->set( 'my_course_page',$new_my_course_page_id ); |
|
| 246 | 246 | |
| 247 | 247 | } // End create_pages() |
| 248 | 248 | |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | wp_register_style( 'woothemes-sensei-global', Sensei()->plugin_url . 'assets/css/global.css', '', Sensei()->version, 'screen' ); |
| 264 | 264 | wp_enqueue_style( 'woothemes-sensei-global' ); |
| 265 | 265 | |
| 266 | - // Select 2 styles |
|
| 267 | - wp_enqueue_style( 'sensei-core-select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' ); |
|
| 266 | + // Select 2 styles |
|
| 267 | + wp_enqueue_style( 'sensei-core-select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' ); |
|
| 268 | 268 | |
| 269 | 269 | // Test for Write Panel Pages |
| 270 | 270 | if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) { |
@@ -277,32 +277,32 @@ discard block |
||
| 277 | 277 | } // End admin_styles_global() |
| 278 | 278 | |
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * Globally register all scripts needed in admin. |
|
| 282 | - * |
|
| 283 | - * The script users should enqueue the script when needed. |
|
| 284 | - * |
|
| 285 | - * @since 1.8.2 |
|
| 286 | - * @access public |
|
| 287 | - */ |
|
| 288 | - public function register_scripts( $hook ){ |
|
| 280 | + /** |
|
| 281 | + * Globally register all scripts needed in admin. |
|
| 282 | + * |
|
| 283 | + * The script users should enqueue the script when needed. |
|
| 284 | + * |
|
| 285 | + * @since 1.8.2 |
|
| 286 | + * @access public |
|
| 287 | + */ |
|
| 288 | + public function register_scripts( $hook ){ |
|
| 289 | 289 | |
| 290 | - $screen = get_current_screen(); |
|
| 290 | + $screen = get_current_screen(); |
|
| 291 | 291 | |
| 292 | - // Allow developers to load non-minified versions of scripts |
|
| 293 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 292 | + // Allow developers to load non-minified versions of scripts |
|
| 293 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 294 | 294 | |
| 295 | - // Select2 script used to enhance all select boxes |
|
| 296 | - wp_register_script( 'sensei-core-select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
| 295 | + // Select2 script used to enhance all select boxes |
|
| 296 | + wp_register_script( 'sensei-core-select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
| 297 | 297 | |
| 298 | - // load edit module scripts |
|
| 299 | - if( 'edit-module' == $screen->id ){ |
|
| 298 | + // load edit module scripts |
|
| 299 | + if( 'edit-module' == $screen->id ){ |
|
| 300 | 300 | |
| 301 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true ); |
|
| 301 | + wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true ); |
|
| 302 | 302 | |
| 303 | - } |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | * @return void |
| 313 | 313 | */ |
| 314 | 314 | function admin_install_notice() { |
| 315 | - ?> |
|
| 315 | + ?> |
|
| 316 | 316 | <div id="message" class="updated sensei-message sensei-connect"> |
| 317 | 317 | |
| 318 | 318 | <p> |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | * @return void |
| 348 | 348 | */ |
| 349 | 349 | function admin_installed_notice() { |
| 350 | - ?> |
|
| 350 | + ?> |
|
| 351 | 351 | <div id="message" class="updated sensei-message sensei-connect"> |
| 352 | 352 | |
| 353 | 353 | <p> |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | </div> |
| 376 | 376 | <?php |
| 377 | 377 | |
| 378 | - // Set installed option |
|
| 379 | - update_option('sensei_installed', 0); |
|
| 378 | + // Set installed option |
|
| 379 | + update_option('sensei_installed', 0); |
|
| 380 | 380 | } // End admin_installed_notice() |
| 381 | 381 | |
| 382 | 382 | |
@@ -408,21 +408,21 @@ discard block |
||
| 408 | 408 | function admin_notices_styles() { |
| 409 | 409 | |
| 410 | 410 | // Installed notices |
| 411 | - if ( 1 == get_option( 'sensei_installed' ) ) { |
|
| 411 | + if ( 1 == get_option( 'sensei_installed' ) ) { |
|
| 412 | 412 | |
| 413 | - wp_enqueue_style( 'sensei-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version ); |
|
| 413 | + wp_enqueue_style( 'sensei-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version ); |
|
| 414 | 414 | |
| 415 | - if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) { |
|
| 416 | - add_action( 'admin_notices', array( $this, 'admin_install_notice' ) ); |
|
| 417 | - } elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) { |
|
| 418 | - add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) ); |
|
| 419 | - } // End If Statement |
|
| 415 | + if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) { |
|
| 416 | + add_action( 'admin_notices', array( $this, 'admin_install_notice' ) ); |
|
| 417 | + } elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) { |
|
| 418 | + add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) ); |
|
| 419 | + } // End If Statement |
|
| 420 | 420 | |
| 421 | - } // End If Statement |
|
| 421 | + } // End If Statement |
|
| 422 | 422 | |
| 423 | - if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) { |
|
| 424 | - add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) ); |
|
| 425 | - } |
|
| 423 | + if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) { |
|
| 424 | + add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) ); |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | 427 | } // End admin_notices_styles() |
| 428 | 428 | |
@@ -538,30 +538,30 @@ discard block |
||
| 538 | 538 | */ |
| 539 | 539 | private function duplicate_lesson_quizzes( $old_lesson_id, $new_lesson_id ) { |
| 540 | 540 | |
| 541 | - $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id ); |
|
| 542 | - $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id ); |
|
| 541 | + $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id ); |
|
| 542 | + $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id ); |
|
| 543 | 543 | |
| 544 | - // duplicate the generic wp post information |
|
| 544 | + // duplicate the generic wp post information |
|
| 545 | 545 | $new_quiz = $this->duplicate_post( get_post( $old_quiz_id ), '' ); |
| 546 | 546 | |
| 547 | 547 | //update the new lesson data |
| 548 | - add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID ); |
|
| 548 | + add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID ); |
|
| 549 | 549 | |
| 550 | 550 | //update the new quiz data |
| 551 | - add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id ); |
|
| 552 | - wp_update_post( |
|
| 553 | - array( |
|
| 554 | - 'ID' => $new_quiz->ID, |
|
| 555 | - 'post_parent' => $new_lesson_id |
|
| 556 | - ) |
|
| 557 | - ); |
|
| 551 | + add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id ); |
|
| 552 | + wp_update_post( |
|
| 553 | + array( |
|
| 554 | + 'ID' => $new_quiz->ID, |
|
| 555 | + 'post_parent' => $new_lesson_id |
|
| 556 | + ) |
|
| 557 | + ); |
|
| 558 | 558 | |
| 559 | 559 | foreach( $old_quiz_questions as $question ) { |
| 560 | 560 | |
| 561 | 561 | // copy the question order over to the new quiz |
| 562 | 562 | $old_question_order = get_post_meta( $question->ID, '_quiz_question_order'. $old_quiz_id, true ); |
| 563 | - $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order ); |
|
| 564 | - add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order ); |
|
| 563 | + $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order ); |
|
| 564 | + add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order ); |
|
| 565 | 565 | |
| 566 | 566 | // Add question to quiz |
| 567 | 567 | add_post_meta( $question->ID, '_quiz_id', $new_quiz->ID, false ); |
@@ -883,21 +883,21 @@ discard block |
||
| 883 | 883 | break; |
| 884 | 884 | |
| 885 | 885 | case 'checkbox': |
| 886 | - //backwards compatibility |
|
| 887 | - if( empty( $data ) || 'on' == $data ){ |
|
| 888 | - $checked_value = 'on'; |
|
| 889 | - }elseif( 'yes' == $data ) { |
|
| 886 | + //backwards compatibility |
|
| 887 | + if( empty( $data ) || 'on' == $data ){ |
|
| 888 | + $checked_value = 'on'; |
|
| 889 | + }elseif( 'yes' == $data ) { |
|
| 890 | 890 | |
| 891 | - $checked_value = 'yes'; |
|
| 891 | + $checked_value = 'yes'; |
|
| 892 | 892 | |
| 893 | - }elseif( 'auto' == $data ) { |
|
| 893 | + }elseif( 'auto' == $data ) { |
|
| 894 | 894 | |
| 895 | - $checked_value = 'auto'; |
|
| 895 | + $checked_value = 'auto'; |
|
| 896 | 896 | |
| 897 | - } else { |
|
| 898 | - $checked_value = 1; |
|
| 899 | - $data = intval( $data ); |
|
| 900 | - } |
|
| 897 | + } else { |
|
| 898 | + $checked_value = 1; |
|
| 899 | + $data = intval( $data ); |
|
| 900 | + } |
|
| 901 | 901 | $checked = checked( $checked_value, $data, false ); |
| 902 | 902 | $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" ' . $checked . ' ' . $disabled . '/>' . "\n"; |
| 903 | 903 | break; |
@@ -1001,26 +1001,26 @@ discard block |
||
| 1001 | 1001 | |
| 1002 | 1002 | if( 0 < count( $courses ) ) { |
| 1003 | 1003 | |
| 1004 | - // order the courses as set by the users |
|
| 1005 | - $all_course_ids = array(); |
|
| 1006 | - foreach( $courses as $course ){ |
|
| 1004 | + // order the courses as set by the users |
|
| 1005 | + $all_course_ids = array(); |
|
| 1006 | + foreach( $courses as $course ){ |
|
| 1007 | 1007 | |
| 1008 | - $all_course_ids[] = (string)$course->ID; |
|
| 1008 | + $all_course_ids[] = (string)$course->ID; |
|
| 1009 | 1009 | |
| 1010 | - } |
|
| 1011 | - $order_string = $this->get_course_order(); |
|
| 1010 | + } |
|
| 1011 | + $order_string = $this->get_course_order(); |
|
| 1012 | 1012 | |
| 1013 | - if( !empty( $order_string ) ){ |
|
| 1014 | - $ordered_course_ids = explode(',' , $order_string ); |
|
| 1015 | - $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) ); |
|
| 1016 | - } |
|
| 1013 | + if( !empty( $order_string ) ){ |
|
| 1014 | + $ordered_course_ids = explode(',' , $order_string ); |
|
| 1015 | + $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) ); |
|
| 1016 | + } |
|
| 1017 | 1017 | |
| 1018 | 1018 | |
| 1019 | 1019 | $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
| 1020 | 1020 | $html .= '<ul class="sortable-course-list">' . "\n"; |
| 1021 | 1021 | $count = 0; |
| 1022 | 1022 | foreach ( $all_course_ids as $course_id ) { |
| 1023 | - $course = get_post( $course_id ); |
|
| 1023 | + $course = get_post( $course_id ); |
|
| 1024 | 1024 | $count++; |
| 1025 | 1025 | $class = 'course'; |
| 1026 | 1026 | if ( $count == 1 ) { $class .= ' first'; } |
@@ -1135,73 +1135,73 @@ discard block |
||
| 1135 | 1135 | |
| 1136 | 1136 | $displayed_lessons = array(); |
| 1137 | 1137 | |
| 1138 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
| 1139 | - |
|
| 1140 | - foreach( $modules as $module ) { |
|
| 1141 | - |
|
| 1142 | - $args = array( |
|
| 1143 | - 'post_type' => 'lesson', |
|
| 1144 | - 'post_status' => 'publish', |
|
| 1145 | - 'posts_per_page' => -1, |
|
| 1146 | - 'meta_query' => array( |
|
| 1147 | - array( |
|
| 1148 | - 'key' => '_lesson_course', |
|
| 1149 | - 'value' => intval( $course_id ), |
|
| 1150 | - 'compare' => '=' |
|
| 1151 | - ) |
|
| 1152 | - ), |
|
| 1153 | - 'tax_query' => array( |
|
| 1154 | - array( |
|
| 1155 | - 'taxonomy' => Sensei()->modules->taxonomy, |
|
| 1156 | - 'field' => 'id', |
|
| 1157 | - 'terms' => intval( $module->term_id ) |
|
| 1158 | - ) |
|
| 1159 | - ), |
|
| 1160 | - 'meta_key' => '_order_module_' . $module->term_id, |
|
| 1161 | - 'orderby' => 'meta_value_num date', |
|
| 1162 | - 'order' => 'ASC', |
|
| 1163 | - 'suppress_filters' => 0 |
|
| 1164 | - ); |
|
| 1165 | - |
|
| 1166 | - $lessons = get_posts( $args ); |
|
| 1167 | - |
|
| 1168 | - if( count( $lessons ) > 0 ) { |
|
| 1169 | - $html .= '<h3>' . $module->name . '</h3>' . "\n"; |
|
| 1170 | - $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n"; |
|
| 1171 | - |
|
| 1172 | - $count = 0; |
|
| 1173 | - foreach( $lessons as $lesson ) { |
|
| 1174 | - $count++; |
|
| 1175 | - $class = 'lesson'; |
|
| 1176 | - if ( $count == 1 ) { $class .= ' first'; } |
|
| 1177 | - if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
| 1178 | - if ( $count % 2 != 0 ) { |
|
| 1179 | - $class .= ' alternate'; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
| 1183 | - |
|
| 1184 | - $displayed_lessons[] = $lesson->ID; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - $html .= '</ul>' . "\n"; |
|
| 1188 | - |
|
| 1189 | - $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n"; |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - |
|
| 1194 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 1138 | + $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
| 1139 | + |
|
| 1140 | + foreach( $modules as $module ) { |
|
| 1141 | + |
|
| 1142 | + $args = array( |
|
| 1143 | + 'post_type' => 'lesson', |
|
| 1144 | + 'post_status' => 'publish', |
|
| 1145 | + 'posts_per_page' => -1, |
|
| 1146 | + 'meta_query' => array( |
|
| 1147 | + array( |
|
| 1148 | + 'key' => '_lesson_course', |
|
| 1149 | + 'value' => intval( $course_id ), |
|
| 1150 | + 'compare' => '=' |
|
| 1151 | + ) |
|
| 1152 | + ), |
|
| 1153 | + 'tax_query' => array( |
|
| 1154 | + array( |
|
| 1155 | + 'taxonomy' => Sensei()->modules->taxonomy, |
|
| 1156 | + 'field' => 'id', |
|
| 1157 | + 'terms' => intval( $module->term_id ) |
|
| 1158 | + ) |
|
| 1159 | + ), |
|
| 1160 | + 'meta_key' => '_order_module_' . $module->term_id, |
|
| 1161 | + 'orderby' => 'meta_value_num date', |
|
| 1162 | + 'order' => 'ASC', |
|
| 1163 | + 'suppress_filters' => 0 |
|
| 1164 | + ); |
|
| 1165 | + |
|
| 1166 | + $lessons = get_posts( $args ); |
|
| 1167 | + |
|
| 1168 | + if( count( $lessons ) > 0 ) { |
|
| 1169 | + $html .= '<h3>' . $module->name . '</h3>' . "\n"; |
|
| 1170 | + $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n"; |
|
| 1171 | + |
|
| 1172 | + $count = 0; |
|
| 1173 | + foreach( $lessons as $lesson ) { |
|
| 1174 | + $count++; |
|
| 1175 | + $class = 'lesson'; |
|
| 1176 | + if ( $count == 1 ) { $class .= ' first'; } |
|
| 1177 | + if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
| 1178 | + if ( $count % 2 != 0 ) { |
|
| 1179 | + $class .= ' alternate'; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
| 1183 | + |
|
| 1184 | + $displayed_lessons[] = $lesson->ID; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + $html .= '</ul>' . "\n"; |
|
| 1188 | + |
|
| 1189 | + $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n"; |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + |
|
| 1194 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 1195 | 1195 | |
| 1196 | 1196 | if( 0 < count( $lessons ) ) { |
| 1197 | 1197 | |
| 1198 | - //get module term ids, will be used to exclude lessons |
|
| 1199 | - $module_items_ids = array(); |
|
| 1200 | - if( ! empty( $modules ) ) { |
|
| 1201 | - foreach ($modules as $module) { |
|
| 1202 | - $module_items_ids[] = $module->term_id; |
|
| 1203 | - } |
|
| 1204 | - } |
|
| 1198 | + //get module term ids, will be used to exclude lessons |
|
| 1199 | + $module_items_ids = array(); |
|
| 1200 | + if( ! empty( $modules ) ) { |
|
| 1201 | + foreach ($modules as $module) { |
|
| 1202 | + $module_items_ids[] = $module->term_id; |
|
| 1203 | + } |
|
| 1204 | + } |
|
| 1205 | 1205 | |
| 1206 | 1206 | if( 0 < count( $displayed_lessons ) ) { |
| 1207 | 1207 | $html .= '<h3>' . __( 'Other Lessons', 'woothemes-sensei' ) . '</h3>' . "\n"; |
@@ -1211,13 +1211,13 @@ discard block |
||
| 1211 | 1211 | $count = 0; |
| 1212 | 1212 | foreach ( $lessons as $lesson ) { |
| 1213 | 1213 | |
| 1214 | - // if lesson belongs to one fo the course modules then exclude it here |
|
| 1215 | - // as it is listed above |
|
| 1216 | - if( has_term( $module_items_ids, 'module', $lesson->ID ) ){ |
|
| 1214 | + // if lesson belongs to one fo the course modules then exclude it here |
|
| 1215 | + // as it is listed above |
|
| 1216 | + if( has_term( $module_items_ids, 'module', $lesson->ID ) ){ |
|
| 1217 | 1217 | |
| 1218 | - continue; |
|
| 1218 | + continue; |
|
| 1219 | 1219 | |
| 1220 | - } |
|
| 1220 | + } |
|
| 1221 | 1221 | |
| 1222 | 1222 | $count++; |
| 1223 | 1223 | $class = 'lesson'; |
@@ -1261,28 +1261,28 @@ discard block |
||
| 1261 | 1261 | |
| 1262 | 1262 | if( $course_id ) { |
| 1263 | 1263 | |
| 1264 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
| 1264 | + $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
| 1265 | 1265 | |
| 1266 | - foreach( $modules as $module ) { |
|
| 1266 | + foreach( $modules as $module ) { |
|
| 1267 | 1267 | |
| 1268 | 1268 | |
| 1269 | - if( isset( $_POST[ 'lesson-order-module-' . $module->term_id ] ) |
|
| 1270 | - && $_POST[ 'lesson-order-module-' . $module->term_id ] ) { |
|
| 1269 | + if( isset( $_POST[ 'lesson-order-module-' . $module->term_id ] ) |
|
| 1270 | + && $_POST[ 'lesson-order-module-' . $module->term_id ] ) { |
|
| 1271 | 1271 | |
| 1272 | - $order = explode( ',', $_POST[ 'lesson-order-module-' . $module->term_id ] ); |
|
| 1273 | - $i = 1; |
|
| 1274 | - foreach( $order as $lesson_id ) { |
|
| 1272 | + $order = explode( ',', $_POST[ 'lesson-order-module-' . $module->term_id ] ); |
|
| 1273 | + $i = 1; |
|
| 1274 | + foreach( $order as $lesson_id ) { |
|
| 1275 | 1275 | |
| 1276 | - if( $lesson_id ) { |
|
| 1277 | - update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i ); |
|
| 1278 | - ++$i; |
|
| 1279 | - } |
|
| 1276 | + if( $lesson_id ) { |
|
| 1277 | + update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i ); |
|
| 1278 | + ++$i; |
|
| 1279 | + } |
|
| 1280 | 1280 | |
| 1281 | - }// end for each order |
|
| 1281 | + }// end for each order |
|
| 1282 | 1282 | |
| 1283 | - }// end if |
|
| 1283 | + }// end if |
|
| 1284 | 1284 | |
| 1285 | - } // end for each modules |
|
| 1285 | + } // end for each modules |
|
| 1286 | 1286 | |
| 1287 | 1287 | |
| 1288 | 1288 | if( $order_string ) { |
@@ -1365,47 +1365,47 @@ discard block |
||
| 1365 | 1365 | |
| 1366 | 1366 | /** |
| 1367 | 1367 | * Adding admin notice if the current |
| 1368 | - * installed theme is not compatible |
|
| 1369 | - * |
|
| 1368 | + * installed theme is not compatible |
|
| 1369 | + * |
|
| 1370 | 1370 | * @return void |
| 1371 | 1371 | */ |
| 1372 | 1372 | public function theme_compatibility_notices() { |
| 1373 | 1373 | |
| 1374 | - if( isset( $_GET['sensei_hide_notice'] ) ) { |
|
| 1375 | - switch( esc_attr( $_GET['sensei_hide_notice'] ) ) { |
|
| 1374 | + if( isset( $_GET['sensei_hide_notice'] ) ) { |
|
| 1375 | + switch( esc_attr( $_GET['sensei_hide_notice'] ) ) { |
|
| 1376 | 1376 | case 'menu_settings': add_user_meta( get_current_user_id(), 'sensei_hide_menu_settings_notice', true ); break; |
| 1377 | 1377 | case 'theme_check': add_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); break; |
| 1378 | 1378 | } |
| 1379 | - } |
|
| 1379 | + } |
|
| 1380 | 1380 | |
| 1381 | - // white list templates that are already support by default and do not show notice for them |
|
| 1382 | - $template = get_option( 'template' ); |
|
| 1381 | + // white list templates that are already support by default and do not show notice for them |
|
| 1382 | + $template = get_option( 'template' ); |
|
| 1383 | 1383 | |
| 1384 | - $white_list = array( 'twentyeleven', |
|
| 1385 | - 'twentytwelve', |
|
| 1386 | - 'twentyfourteen', |
|
| 1387 | - 'twentyfifteen', |
|
| 1388 | - 'twentysixteen', |
|
| 1389 | - 'storefront', |
|
| 1390 | - ); |
|
| 1384 | + $white_list = array( 'twentyeleven', |
|
| 1385 | + 'twentytwelve', |
|
| 1386 | + 'twentyfourteen', |
|
| 1387 | + 'twentyfifteen', |
|
| 1388 | + 'twentysixteen', |
|
| 1389 | + 'storefront', |
|
| 1390 | + ); |
|
| 1391 | 1391 | |
| 1392 | - if ( in_array( $template, $white_list ) ) { |
|
| 1392 | + if ( in_array( $template, $white_list ) ) { |
|
| 1393 | 1393 | |
| 1394 | - return; |
|
| 1394 | + return; |
|
| 1395 | 1395 | |
| 1396 | - } |
|
| 1396 | + } |
|
| 1397 | 1397 | |
| 1398 | - // don't show the notice if the user chose to hide it |
|
| 1399 | - $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); |
|
| 1400 | - if( $hide_theme_check_notice ) { |
|
| 1398 | + // don't show the notice if the user chose to hide it |
|
| 1399 | + $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); |
|
| 1400 | + if( $hide_theme_check_notice ) { |
|
| 1401 | 1401 | |
| 1402 | - return; |
|
| 1402 | + return; |
|
| 1403 | 1403 | |
| 1404 | - } |
|
| 1404 | + } |
|
| 1405 | 1405 | |
| 1406 | - // show the notice for themes not supporting sensei |
|
| 1407 | - if ( ! current_theme_supports( 'sensei' ) ) { |
|
| 1408 | - ?> |
|
| 1406 | + // show the notice for themes not supporting sensei |
|
| 1407 | + if ( ! current_theme_supports( 'sensei' ) ) { |
|
| 1408 | + ?> |
|
| 1409 | 1409 | |
| 1410 | 1410 | <div id="message" class="error sensei-message sensei-connect"> |
| 1411 | 1411 | <p> |
@@ -1441,7 +1441,7 @@ discard block |
||
| 1441 | 1441 | public function reset_theme_check_notices() { |
| 1442 | 1442 | global $current_user; |
| 1443 | 1443 | wp_get_current_user(); |
| 1444 | - $user_id = $current_user->ID; |
|
| 1444 | + $user_id = $current_user->ID; |
|
| 1445 | 1445 | |
| 1446 | 1446 | delete_user_meta( $user_id, 'sensei_hide_theme_check_notice' ); |
| 1447 | 1447 | } |
@@ -1461,62 +1461,62 @@ discard block |
||
| 1461 | 1461 | return $prevent_access; |
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 1464 | - /** |
|
| 1465 | - * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args |
|
| 1466 | - * on the sensei settings page. |
|
| 1467 | - * |
|
| 1468 | - * The function |
|
| 1469 | - * |
|
| 1470 | - * @since 1.8.7 |
|
| 1471 | - */ |
|
| 1472 | - public static function install_pages(){ |
|
| 1464 | + /** |
|
| 1465 | + * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args |
|
| 1466 | + * on the sensei settings page. |
|
| 1467 | + * |
|
| 1468 | + * The function |
|
| 1469 | + * |
|
| 1470 | + * @since 1.8.7 |
|
| 1471 | + */ |
|
| 1472 | + public static function install_pages(){ |
|
| 1473 | 1473 | |
| 1474 | - // only fire on the settings page |
|
| 1475 | - if( ! isset( $_GET['page'] ) |
|
| 1476 | - || 'woothemes-sensei-settings' != $_GET['page'] |
|
| 1477 | - || 1 == get_option('skip_install_sensei_pages') ){ |
|
| 1474 | + // only fire on the settings page |
|
| 1475 | + if( ! isset( $_GET['page'] ) |
|
| 1476 | + || 'woothemes-sensei-settings' != $_GET['page'] |
|
| 1477 | + || 1 == get_option('skip_install_sensei_pages') ){ |
|
| 1478 | 1478 | |
| 1479 | - return; |
|
| 1479 | + return; |
|
| 1480 | 1480 | |
| 1481 | - } |
|
| 1481 | + } |
|
| 1482 | 1482 | |
| 1483 | - // Install/page installer |
|
| 1484 | - $install_complete = false; |
|
| 1483 | + // Install/page installer |
|
| 1484 | + $install_complete = false; |
|
| 1485 | 1485 | |
| 1486 | - // Add pages button |
|
| 1487 | - $settings_url = ''; |
|
| 1488 | - if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) { |
|
| 1486 | + // Add pages button |
|
| 1487 | + $settings_url = ''; |
|
| 1488 | + if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) { |
|
| 1489 | 1489 | |
| 1490 | - Sensei()->admin->create_pages(); |
|
| 1490 | + Sensei()->admin->create_pages(); |
|
| 1491 | 1491 | |
| 1492 | - update_option('skip_install_sensei_pages', 1); |
|
| 1492 | + update_option('skip_install_sensei_pages', 1); |
|
| 1493 | 1493 | |
| 1494 | - $install_complete = true; |
|
| 1495 | - $settings_url = remove_query_arg('install_sensei_pages'); |
|
| 1494 | + $install_complete = true; |
|
| 1495 | + $settings_url = remove_query_arg('install_sensei_pages'); |
|
| 1496 | 1496 | |
| 1497 | - // Skip button |
|
| 1498 | - } elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) { |
|
| 1497 | + // Skip button |
|
| 1498 | + } elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) { |
|
| 1499 | 1499 | |
| 1500 | - update_option('skip_install_sensei_pages', 1); |
|
| 1501 | - $install_complete = true; |
|
| 1502 | - $settings_url = remove_query_arg('skip_install_sensei_pages'); |
|
| 1500 | + update_option('skip_install_sensei_pages', 1); |
|
| 1501 | + $install_complete = true; |
|
| 1502 | + $settings_url = remove_query_arg('skip_install_sensei_pages'); |
|
| 1503 | 1503 | |
| 1504 | - } |
|
| 1504 | + } |
|
| 1505 | 1505 | |
| 1506 | - if ($install_complete) { |
|
| 1506 | + if ($install_complete) { |
|
| 1507 | 1507 | |
| 1508 | - // refresh the rewrite rules on init |
|
| 1509 | - update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1508 | + // refresh the rewrite rules on init |
|
| 1509 | + update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1510 | 1510 | |
| 1511 | - // Set installed option |
|
| 1512 | - update_option('sensei_installed', 0); |
|
| 1511 | + // Set installed option |
|
| 1512 | + update_option('sensei_installed', 0); |
|
| 1513 | 1513 | |
| 1514 | - $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url ); |
|
| 1515 | - wp_redirect( $complete_url ); |
|
| 1514 | + $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url ); |
|
| 1515 | + wp_redirect( $complete_url ); |
|
| 1516 | 1516 | |
| 1517 | - } |
|
| 1517 | + } |
|
| 1518 | 1518 | |
| 1519 | - }// end install_pages |
|
| 1519 | + }// end install_pages |
|
| 1520 | 1520 | |
| 1521 | 1521 | } // End Class |
| 1522 | 1522 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function register_hook_listener() { |
| 59 | 59 | |
| 60 | - add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 ); |
|
| 60 | + add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 ); |
|
| 61 | 61 | add_action( 'admin_init', array( $this, 'settings_fields' ) ); |
| 62 | - add_action( 'init', array( $this, 'general_init' ), 5 ); |
|
| 62 | + add_action( 'init', array( $this, 'general_init' ), 5 ); |
|
| 63 | 63 | |
| 64 | 64 | } // End setup_settings() |
| 65 | 65 | |
@@ -293,14 +293,14 @@ discard block |
||
| 293 | 293 | * @return void |
| 294 | 294 | */ |
| 295 | 295 | public function settings_screen () |
| 296 | - { |
|
| 296 | + { |
|
| 297 | 297 | |
| 298 | - ?> |
|
| 298 | + ?> |
|
| 299 | 299 | <div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>"> |
| 300 | 300 | <?php screen_icon('woothemes-sensei'); ?> |
| 301 | 301 | <h2><?php echo esc_html($this->name); ?><?php if ('' != $this->settings_version) { |
| 302 | - echo ' <span class="version">' . $this->settings_version . '</span>'; |
|
| 303 | - } ?></h2> |
|
| 302 | + echo ' <span class="version">' . $this->settings_version . '</span>'; |
|
| 303 | + } ?></h2> |
|
| 304 | 304 | <p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" |
| 305 | 305 | title="WooThemes"><img |
| 306 | 306 | src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes"/></a></p> |
@@ -308,26 +308,26 @@ discard block |
||
| 308 | 308 | <form action="options.php" method="post"> |
| 309 | 309 | |
| 310 | 310 | <?php |
| 311 | - $this->settings_tabs(); |
|
| 312 | - settings_fields($this->token); |
|
| 313 | - $page = 'woothemes-sensei-settings'; |
|
| 314 | - foreach ($this->sections as $section_id => $section) { |
|
| 311 | + $this->settings_tabs(); |
|
| 312 | + settings_fields($this->token); |
|
| 313 | + $page = 'woothemes-sensei-settings'; |
|
| 314 | + foreach ($this->sections as $section_id => $section) { |
|
| 315 | 315 | |
| 316 | - echo '<section id="' . $section_id . '">'; |
|
| 316 | + echo '<section id="' . $section_id . '">'; |
|
| 317 | 317 | |
| 318 | - if ($section['name']) |
|
| 319 | - echo "<h2>{$section['name']}</h2>\n"; |
|
| 318 | + if ($section['name']) |
|
| 319 | + echo "<h2>{$section['name']}</h2>\n"; |
|
| 320 | 320 | |
| 321 | - echo '<table class="form-table">'; |
|
| 322 | - do_settings_fields($page, $section_id ); |
|
| 323 | - echo '</table>'; |
|
| 321 | + echo '<table class="form-table">'; |
|
| 322 | + do_settings_fields($page, $section_id ); |
|
| 323 | + echo '</table>'; |
|
| 324 | 324 | |
| 325 | - echo '</section>'; |
|
| 325 | + echo '</section>'; |
|
| 326 | 326 | |
| 327 | - } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - submit_button(); |
|
| 330 | - ?> |
|
| 329 | + submit_button(); |
|
| 330 | + ?> |
|
| 331 | 331 | </form> |
| 332 | 332 | <?php do_action( 'settings_after_form' ); ?> |
| 333 | 333 | </div><!--/#woothemes-sensei--> |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | */ |
| 343 | 343 | public function get_settings () { |
| 344 | 344 | |
| 345 | - $this->settings = get_option( $this->token, array() ); |
|
| 345 | + $this->settings = get_option( $this->token, array() ); |
|
| 346 | 346 | |
| 347 | 347 | foreach ( $this->fields as $k => $v ) { |
| 348 | 348 | if ( ! isset( $this->settings[$k] ) && isset( $v['default'] ) ) { |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | * @return void |
| 376 | 376 | */ |
| 377 | 377 | public function settings_errors () { |
| 378 | - settings_errors( $this->token . '-errors' ); |
|
| 378 | + settings_errors( $this->token . '-errors' ); |
|
| 379 | 379 | } // End settings_errors() |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -441,9 +441,9 @@ discard block |
||
| 441 | 441 | echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n"; |
| 442 | 442 | if ( $has_description ) { |
| 443 | 443 | echo wp_kses( $args['data']['description'], array( 'a' => array( |
| 444 | - 'href' => array(), |
|
| 445 | - 'title' => array() |
|
| 446 | - ) |
|
| 444 | + 'href' => array(), |
|
| 445 | + 'title' => array() |
|
| 446 | + ) |
|
| 447 | 447 | ) |
| 448 | 448 | ) . '</label>' . "\n"; |
| 449 | 449 | } |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | */ |
| 833 | 833 | public function enqueue_scripts () { |
| 834 | 834 | |
| 835 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 835 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 836 | 836 | |
| 837 | 837 | wp_enqueue_script( 'farbtastic' ); |
| 838 | 838 | wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version ); |