alex or mr vibe certificate course completion date

Home Forums Legacy Support Support queries Setup issues alex or mr vibe certificate course completion date

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #371240
    EduMEE2
    Participant
    course completion code sometimes give new completion date. some time it gives older date. situation: my user access same course every year. the completion date shortcode not working. note: i am using multisite and still using wplms version 3.9.8 or give me more accurate code for course completion date: something like this
    
    add_shortcode('certificate_course_start_date',function($atts, $content = null){
    
    $uid=$_GET['u'];
    
    $cid=$_GET['c'];
    
    global $bp,$wpdb;
    
     
    
    if(isset($uid) && is_numeric($uid) && isset($cid) && is_numeric($cid) && get_post_type($cid) == 'course'){
    
    $course_submission_date = $wpdb->get_var($wpdb->prepare( "
    
    SELECT activity.date_recorded FROM {$bp->activity->table_name} AS activity
    
    WHERE   activity.component  = 'course'
    
    AND     activity.type   = 'start_course'
    
    AND     user_id = %d
    
    AND     item_id = %d
    
    ORDER BY date_recorded DESC LIMIT 0,1
    
    " ,$uid,$cid));
    
     
    
    return date_i18n(get_option( 'date_format' ), strtotime($course_submission_date));
    
    }
    
    return '[certificate_course_start_date]';
    
     
    
    });
    #371318
    Veronica
    Moderator
    hi i hope you have added the same code:
    add_shortcode('certificate_course_start_date',function($atts, $content = null){
    
    $uid=$_GET['u'];
    
    $cid=$_GET['c'];
    
    global $bp,$wpdb;
    
    if(isset($uid) && is_numeric($uid) && isset($cid) && is_numeric($cid) && get_post_type($cid) == 'course'){
    
    $course_submission_date = $wpdb->get_var($wpdb->prepare( "
    
    SELECT activity.date_recorded FROM {$bp->activity->table_name} AS activity
    
    WHERE   activity.component  = 'course'
    
    AND     activity.type   = 'start_course'
    
    AND     user_id = %d
    
    AND     item_id = %d
    
    ORDER BY date_recorded DESC LIMIT 0,1
    
    " ,$uid,$cid));
    
    return date_i18n(get_option( 'date_format' ), strtotime($course_submission_date));
    
    }
    return '[certificate_course_start_date]';
    
    });
    and using [certificate_course_start_date] shortcode' also, regenerate the certificate for the user then assign new one
    #371376
    EduMEE2
    Participant
    please ask help from #alex in this. i dont think you can help in this. the issue is with course completion date code. it's my code to sync the generated certificate code with the "document manager plugin". in this video you can understand what am i doing: http://somup.com/crQ3FPrdbP when pdf certificate is generated in the media folder. i sync the same certificate with "document manager plugin". then user can download it. what is the issue?? the course completion date is showing weired. sometimes it shows fine like in video "22 september 2021" but when same course is completed 2 times. then it should show the latest course completion date. but sometimes it shows the older date means the first time when you completed the course. i think i am missing something in this code with date thing.
    add_shortcode('certificate_link',function( $atts,$content = null ){
    	$a = shortcode_atts( array( 'user_id' => ' ', 'course_id' => ' ' ), $atts );
    	
    	global $wpdb;
    	$suffix = $filesize = '';
    	
    	if( !empty($a['course_id']) && !empty($a['user_id']) ){
    		
    		$course_id = esc_attr($a['course_id']);
    		$course_id = (int)$course_id;
    		
    		$user_id = esc_attr($a['user_id']);
    		$user_id = (int)$user_id;
    
    		$user_info = get_userdata($user_id);
    		$userlogin = $user_info->user_login;
    		
    		$admin_user_id = 1; //as users folder is in id 1
    		
    		//get users folder ID
    		$query = "SELECT *  FROM " . $wpdb->prefix . "sp_cu_project  where name = 'Users' ";
      		$result = $wpdb->get_results($query, ARRAY_A);
    		if(count($result)>0){
    			$user_pid = $result[0]['id'];
    		}
    		if( !empty($user_pid) ){
    			//check if user's folder is created in Users' folder
    			$query = "SELECT *  FROM " . $wpdb->prefix . "sp_cu_project  where name = '".$userlogin."'";
    			$res = $wpdb->get_results($query, ARRAY_A);
    			if(count($res)>0){
    				$pid = $res[0]['id'];
    			}else{
    				$wm_insert = array();
    				$wm_insert['name'] = $userlogin;
    				$wm_insert['uid'] = $admin_user_id;
    				$wm_insert['parent'] = $user_pid; //Users Folder
    
    				foreach($wm_insert as $key=>$value){
    					if(is_null($value)){ unset($insert[$key]); }
    				}
    				$wpdb->insert("" . $wpdb->prefix . "sp_cu_project", $wm_insert);
    				do_action('sp_cdm/save_folder', $wpdb->insert_id,$wm_insert);
    				$pid = $wpdb->insert_id;
    
    				cdm_delete_cache();
    			}
    			if( !empty($pid) ){
    				//check user certificate folder
    				$query1 = "SELECT *  FROM " . $wpdb->prefix . "sp_cu_project  where name = 'Certificates' AND parent = $pid ";
    				$res1 = $wpdb->get_results($query1, ARRAY_A);
    				if(count($res1)>0){
    					$c_folderid = $res1[0]['id']; 
    				}else{
    					$wm_insert = array();
    					$wm_insert['name'] = 'Certificates';
    					$wm_insert['uid'] = $admin_user_id;
    					$wm_insert['parent'] = $pid;
    
    					foreach($wm_insert as $key=>$value){
    						if(is_null($value)){ unset($insert[$key]); }
    					}
    					$wpdb->insert("" . $wpdb->prefix . "sp_cu_project", $wm_insert);
    					do_action('sp_cdm/save_folder', $wpdb->insert_id,$wm_insert);
    					$c_folderid = $wpdb->insert_id;
    
    					cdm_delete_cache();
    				}
    			}
    		}
    		
    		$filepath = bp_get_course_certificate('user_id=' . $user_id . '&course_id=' . $course_id);
    		$filepath_certi = strstr($filepath, '?', true);
    		
    		$filename = urldecode( basename( str_replace( array( '%2F', '%5C' ), '/', urlencode( $filepath ) ), $suffix ) );
    		$filename = strstr($filename, '?', true);
    		$filename = apply_filters('sp_cdm/premium/upload/file_name', $filename, $user_id);
    		$filename = strtolower($filename);
        	$filename = sanitize_file_name($filename);
        	$filename = remove_accents($filename);
        	$filename = apply_filters('sp_cdm/premium/upload/file_rename', $filename, $user_id);
    		
    		$headers = get_headers($filepath, true);
    		$filesize = $headers['Content-Length'];
    	
    		$dir = '' . SP_CDM_UPLOADS_DIR . '' . $admin_user_id . '/';
    		$target_path = $dir . $filename;
    		
    		if(is_file($filepath_certi)){
    			echo 'yes<br/>';
    		}else{
    			echo 'no<br/>';
    		}
    		if(file_exists($filepath_certi)){
    			echo 'yes file<br/>';
    		}else{
    			echo 'no file<br/>';
    		}
    		
    		/*if ( copy($filepath_certi, $target_path) ) {
    			echo "Uploaded<br/>";
    			$a = array();
    			$a['name'] = $filename;
    			$a['file'] = $filename;
    			$a['pid'] = $c_folderid;
    			$a['cid'] = 0;
    			$a['notes'] = '';
    			$a['parent'] = 0;
    			$a['uid'] = $admin_user_id; //same as target dir userid
    			$a['file_size'] = $filesize;
    			foreach($a as $key=>$value){ if(is_null($value)){ unset($a[$key]); } }
    			$wpdb->insert(  "".$wpdb->prefix."sp_cu", $a );
    			$insert_id = $wpdb->insert_id;
    		}else {
    		  	echo "File was not uploaded<br/>";
    		}*/
    		if(!@copy("'$filepath_certi'","'$target_path'"))
    		{
    			$errors= error_get_last();
    			echo "COPY ERROR: ".$errors['type'];
    			echo "<br />\n".$errors['message'];
    		} else {
    			echo "File copied from remote!";
    		}
    	}
    	return $user_id.' '.$course_id.' '.$user_pid.' '.$pid.' '.$c_folderid.' '.$filepath_certi.' '.$target_path.' '.$insert_id;
    });
    add_shortcode('delete_certificate',function( $atts,$content = null ){
    	$a = shortcode_atts( array( 'user_id' => ' ', 'course_id' => ' ' ), $atts );
    	
    	global $wpdb;
    	$suffix = $filesize = '';
    	
    	if( !empty($a['course_id']) && !empty($a['user_id']) ){
    		
    		$course_id = esc_attr($a['course_id']);
    		$course_id = (int)$course_id;
    		
    		$user_id = esc_attr($a['user_id']);
    		$user_id = (int)$user_id;
    		
    		$user_info = get_userdata($user_id);
    		$userlogin = $user_info->user_login;
    		
    		$filepath = bp_get_course_certificate('user_id=' . $user_id . '&course_id=' . $course_id);
    		
    		$filename = urldecode( basename( str_replace( array( '%2F', '%5C' ), '/', urlencode( $filepath ) ), $suffix ) );
    		$filename = strstr($filename, '?', true);
    		$filename = apply_filters('sp_cdm/premium/upload/file_name', $filename, $user_id);
    		$filename = strtolower($filename);
        	$filename = sanitize_file_name($filename);
        	$filename = remove_accents($filename);
        	$filename = apply_filters('sp_cdm/premium/upload/file_rename', $filename, $user_id);
    		
    		$query = "SELECT *  FROM " . $wpdb->prefix . "sp_cu_project  where name = '".$userlogin."'";
    		$res = $wpdb->get_results($query, ARRAY_A);
    		if(count($res)>0){
    			$pid = $res[0]['id'];
    		}
    		if(!empty($pid)){
    			$query1 = "SELECT *  FROM " . $wpdb->prefix . "sp_cu_project  where name = 'Certificates' AND parent = $pid ";
    			$res1 = $wpdb->get_results($query1, ARRAY_A);
    			if(count($res1)>0){
    				$c_folderid = $res1[0]['id']; 
    			}
    		}
    		if(!empty($c_folderid))
    		//get file ID
    		$query = "SELECT *  FROM " . $wpdb->prefix . "sp_cu  where name = '".$filename."' AND pid = $c_folderid AND recycle = 0";
      		$result = $wpdb->get_results($query, ARRAY_A);
    		if(count($result)>0){
    			$file_id = $result[0]['id'];
    			cdm_delete_file($file_id);
    		}
    		
    		return $user_id.' '.$course_id.' '.$file_id;
    	}
    });
    #371441
    Anshuman Sahu
    Keymaster
    Om I get it now. The certificate must be showing correct date when instructor assigns certificate from course admin . But it must be showing wrong date when certificate if awarded automatically to the user upon course completion . This is happening while the course was evaluating the certificate is awarded just before the course submission actually ends . Then the shortcode [course_completion_date] is unable to fetch the completion and hence showing current date . try adding this code in your wplms-customizer.php file in wplms customizer plugin :
    add_action('wplms_certificate_earned',function($course_id,$pass,$user_id){
        do_action('wplms_submit_course',$course_id,$user_id);
    },10,3);
    #371514
    EduMEE2
    Participant
    This reply has been marked as private.
    #371605
    EduMEE2
    Participant
    This reply has been marked as private.
    #371668
    Anshuman Sahu
    Keymaster
    1 . no you can simply add wplms-customizer plugin and network enable it . then add the code to it . 2 . yes it will for wplms 3 as well . 3 . I dont think so ,but yes this code will add the submit course activity twice per user submission . But that can be ignored since user finishing course is less frequent than other activities .
    #371694
    EduMEE2
    Participant
    alex please check this topic: https://wplms.io/support/forums/topic/setup-feedback-form/#post-371693
Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘alex or mr vibe certificate course completion date’ is closed to new replies.