/**
  * Send confirmation for enrollment in moodle course
  *
  * @access public
  * @param array $enrolments
  * @return void
  */
 public function send_moodle_enrollment_confirmation($enrolments)
 {
     global $DC_Woodle;
     $moodle_access_url = woodle_get_settings('access_url', 'dc_woodle_general');
     $enrollment_data = array();
     foreach ($enrolments as $enrolment) {
         $post_id = woodle_get_post_by_moodle_id($enrolment['courseid'], 'course');
         $course = get_post($post_id);
         $enrollment_data['email'] = $DC_Woodle->enrollment->wc_order->billing_email;
         $enrollment_data['course_name'] = $course->post_title;
         $enrollment_data['course_url'] = "{$moodle_access_url}/course/view.php?id={$enrolment['courseid']}";
     }
     $this->send_email('DC_Woodle_Emails_New_Enrollment', $enrollment_data);
 }
예제 #2
0
 * New account email (plain)
 *
 */
if (!defined('ABSPATH')) {
    exit;
}
global $DC_Woodle;
?>

<p><?php 
_e('Email: ', $DC_Woodle->text_domain);
echo $credential['email'];
?>
</p>
<p><?php 
_e('Username: '******'email'];
?>
</p>
<p><?php 
_e('Password: '******'email'];
?>
</p>
<p><a href="<?php 
echo woodle_get_settings('access_url', 'dc_woodle_general');
?>
"><?php 
_e('Login Now', $DC_Woodle->text_domain);
?>
</a></p>
 /**
  * Update moodle courses in Wordpress site.
  *
  * @access private
  * @param array $courses
  * @param string $post_type (default: null)
  * @param string $taxonomy (default: null)
  * @param string $meta_key (default: null)
  * @return void
  */
 private function update_posts($courses, $post_type = '', $taxonomy = '', $meta_key = '')
 {
     if (empty($post_type) || !post_type_exists($post_type) || empty($taxonomy) || !taxonomy_exists($taxonomy) || empty($meta_key)) {
         return;
     }
     $course_ids = array();
     $create_wc_product = $post_type == 'product' ? woodle_get_settings('create_wc_product', 'dc_woodle_general') : '';
     if (!empty($courses)) {
         foreach ($courses as $course) {
             if ($course['format'] == 'site') {
                 continue;
             }
             $post_id = woodle_get_post_by_moodle_id($course['id'], $post_type);
             $post_status = 'publish';
             if ($post_type == 'product' && $post_id) {
                 $product = get_post($post_id);
                 $post_status = $product->post_status;
             }
             $args = array('post_title' => $course['fullname'], 'post_name' => $course['shortname'], 'post_content' => $course['summary'], 'post_status' => $post_status);
             if ($post_id) {
                 $args['ID'] = $post_id;
                 $post_id = wp_update_post($args);
                 if ($post_id) {
                     if ($post_type != 'product') {
                         update_post_meta($post_id, '_course_short_name', $course['shortname']);
                         update_post_meta($post_id, '_course_idnumber', $course['idnumber']);
                     }
                     update_post_meta($post_id, '_category_id', (int) $course['categoryid']);
                     update_post_meta($post_id, '_visibility', $course['visible'] ? 'visible' : 'hidden');
                     if ($post_type == 'product') {
                         update_post_meta($post_id, '_virtual', 'yes');
                         update_post_meta($post_id, '_sold_individually', 'yes');
                     }
                 }
             } else {
                 if ($post_type != 'product' || $create_wc_product == 'yes') {
                     $args['post_type'] = $post_type;
                     $post_id = wp_insert_post($args);
                     if ($post_id) {
                         if ($post_type != 'product') {
                             add_post_meta($post_id, '_course_short_name', $course['shortname']);
                             add_post_meta($post_id, '_course_idnumber', $course['idnumber']);
                         }
                         add_post_meta($post_id, '_course_id', (int) $course['id']);
                         add_post_meta($post_id, '_category_id', (int) $course['categoryid']);
                         add_post_meta($post_id, '_visibility', $course['visible'] ? 'visible' : 'hidden');
                         if ($post_type == 'product') {
                             add_post_meta($post_id, '_sku', 'course-' . $course['id']);
                             add_post_meta($post_id, '_virtual', 'yes');
                             add_post_meta($post_id, '_sold_individually', 'yes');
                         }
                     }
                 }
             }
             $course_ids[$course['id']] = $course['categoryid'];
         }
     }
     $posts = woodle_get_posts(array('post_type' => $post_type));
     if ($posts) {
         foreach ($posts as $post) {
             $course_id = get_post_meta($post->ID, '_course_id', true);
             if (array_key_exists($course_id, $course_ids)) {
                 $term_id = woodle_get_term_by_moodle_id($course_ids[$course_id], $taxonomy, $meta_key);
                 wp_set_post_terms($post->ID, $term_id, $taxonomy);
             } else {
                 if (!empty($course_id)) {
                     wp_delete_post($post->ID, false);
                 }
             }
         }
     }
 }
 /**
  * Data required for enrollment.
  *
  * @access private
  * @param int $moodle_user_id (default: int)
  * @param int $suspend (default: int)
  * @return array
  */
 private function get_enrollment_data($moodle_user_id, $suspend = 0)
 {
     global $DC_Woodle;
     $wc_order = $this->wc_order;
     $enrolments = array();
     $items = $wc_order->get_items();
     $role_id = woodle_get_settings('moodle_role_id', 'dc_woodle_general');
     $role_id = empty($role_id) || !intval($role_id) ? 5 : intval($role_id);
     if (!empty($items)) {
         foreach ($items as $item) {
             $course_id = get_post_meta($item['product_id'], '_course_id', true);
             if (!empty($course_id)) {
                 $enrolment = array();
                 $enrolment['courseid'] = $course_id;
                 $enrolment['userid'] = $moodle_user_id;
                 $enrolment['roleid'] = $role_id;
                 $enrolment['suspend'] = $suspend;
                 $enrolments[] = $enrolment;
             }
         }
     }
     return apply_filters('woodle_moodle_enrolments_data', $enrolments);
 }
 function woodle_moodle_core_function_callback($function_name = '', $request_param = null)
 {
     global $DC_Woodle;
     $response = null;
     $url = woodle_get_settings('access_url', 'dc_woodle_general');
     $token = woodle_get_settings('ws_token', 'dc_woodle_general');
     $request_url = $url . '/webservice/xmlrpc/server.php?wstoken=' . $token;
     if (!empty($url) && !empty($token) && $function_name != '') {
         $request = xmlrpc_encode_request($function_name, $request_param);
         $response = wp_remote_post($request_url, array('body' => $request));
     }
     if (!is_wp_error($response) && $response != null) {
         $response = xmlrpc_decode($response['body']);
         if (is_string($response)) {
             $response = json_decode($response, true);
         }
     }
     if (json_last_error() === JSON_ERROR_NONE) {
         if (empty($response) || array_key_exists('faultCode', $response)) {
             $DC_Woodle->sync->has_error = true;
         } else {
             $DC_Woodle->sync->has_error = false;
             return $response;
         }
     }
     return null;
 }