ActionBoxGenerator.php
1 year ago
AnnouncementsGenerator.php
1 year ago
CourseMetaGenerator.php
1 year ago
CourseThumbnailGenerator.php
1 year ago
ElementGenerator.php
1 year ago
GradebookGenerator.php
1 year ago
InstructorGenerator.php
1 year ago
LessonGenerator.php
1 year ago
Preview.php
1 year ago
QnAGenerator.php
1 year ago
RatingGenerator.php
1 year ago
ResourcesGenerator.php
1 year ago
ShareGenerator.php
1 year ago
TopicsGenerator.php
1 year ago
WishListGenerator.php
1 year ago
ActionBoxGenerator.php
255 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Preview script for html markup generator |
| 4 | * |
| 5 | * @package tutor-droip-elements |
| 6 | */ |
| 7 | |
| 8 | namespace TutorLMSDroip\ElementGenerator; |
| 9 | |
| 10 | use TUTOR_CERT\Certificate; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; // Exit if accessed directly. |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Class ActionboxGenerator |
| 18 | * This class is used to define all helper functions. |
| 19 | * |
| 20 | * @package TutorLMSDroip\ElementGenerator |
| 21 | */ |
| 22 | trait ActionboxGenerator { |
| 23 | /** |
| 24 | * Generate actionbox markup |
| 25 | * |
| 26 | * @return string |
| 27 | */ |
| 28 | private function generate_actionbox_markup() { |
| 29 | $course_id = isset( $this->options['post'] ) ? $this->options['post']->ID : get_the_ID(); |
| 30 | $ele_name = $this->element['name']; |
| 31 | switch ( $this->element['name'] ) { |
| 32 | case TDE_APP_PREFIX . '-course-enroll-buttons': |
| 33 | if ( tutor_entry_box_buttons( $course_id )->show_add_to_cart_btn || tutor_entry_box_buttons( $course_id )->show_enroll_btn ) { |
| 34 | return $this->generate_common_element(); |
| 35 | } else { |
| 36 | return ''; |
| 37 | } |
| 38 | case TDE_APP_PREFIX . '-free-action-box': |
| 39 | $price = apply_filters( 'get_tutor_course_price', null, $course_id ); |
| 40 | $is_purchasable = tutor_utils()->is_course_purchasable(); |
| 41 | $is_free = $is_purchasable && $price ? false : true; |
| 42 | if ( ! $is_free ) { |
| 43 | return ''; |
| 44 | } |
| 45 | return $this->generate_common_element(); |
| 46 | |
| 47 | case TDE_APP_PREFIX . '-enroll-button': |
| 48 | if ( ! tutor_entry_box_buttons( $course_id )->show_enroll_btn ) { |
| 49 | return ''; |
| 50 | } |
| 51 | $children_html = $this->generate_child_elements(); |
| 52 | $children_html .= "<input type='hidden' name='course_id' value='$course_id' />"; |
| 53 | return "<div $this->attributes data-ele_name='$ele_name'>$children_html</div>"; |
| 54 | case TDE_APP_PREFIX . '-paid-action-buttons': |
| 55 | if ( tutor_entry_box_buttons( $course_id )->show_add_to_cart_btn ) { |
| 56 | return $this->generate_common_element(); |
| 57 | } else { |
| 58 | return ''; |
| 59 | } |
| 60 | |
| 61 | case TDE_APP_PREFIX . '-cart-box': |
| 62 | if ( ! class_exists( 'WooCommerce' ) ) { |
| 63 | return ''; |
| 64 | } |
| 65 | if ( ! tutor_entry_box_buttons( $course_id )->show_add_to_cart_btn ) { |
| 66 | return ''; |
| 67 | } |
| 68 | $children_html = $this->generate_child_elements(); |
| 69 | return "<div $this->attributes>$children_html</div>"; |
| 70 | |
| 71 | case TDE_APP_PREFIX . '-add-to-cart-button': |
| 72 | if ( ! class_exists( 'WooCommerce' ) ) { |
| 73 | return ''; |
| 74 | } |
| 75 | if ( ! tutor_entry_box_buttons( $course_id )->show_add_to_cart_btn ) { |
| 76 | return ''; |
| 77 | } |
| 78 | |
| 79 | $product_id = tutor_utils()->get_course_product_id( $course_id ); |
| 80 | |
| 81 | if ( tutor_utils()->is_course_added_to_cart( $product_id, true ) ) { |
| 82 | return ''; |
| 83 | } |
| 84 | |
| 85 | $action_url = esc_url( apply_filters( 'tutor_course_add_to_cart_form_action', get_permalink( $course_id ) ) ); |
| 86 | $children_html = $this->generate_child_elements(); |
| 87 | $children_html .= "<input type='hidden' name='action_url' value='$action_url' />"; |
| 88 | $children_html .= "<input type='hidden' name='product_id' value='$product_id' />"; |
| 89 | return $this->generate_common_element( false, $children_html ); |
| 90 | |
| 91 | case TDE_APP_PREFIX . '-view-cart-button': |
| 92 | if ( ! class_exists( 'WooCommerce' ) ) { |
| 93 | return ''; |
| 94 | } |
| 95 | $product_id = tutor_utils()->get_course_product_id( $course_id ); |
| 96 | $product = wc_get_product( $product_id ); |
| 97 | |
| 98 | if ( ! tutor_utils()->is_course_added_to_cart( $product_id, true ) ) { |
| 99 | return ''; |
| 100 | } |
| 101 | |
| 102 | $cart_url = esc_url( wc_get_cart_url() ); |
| 103 | $children_html = $this->generate_child_elements(); |
| 104 | |
| 105 | return "<a href='$cart_url' $this->attributes>$children_html</a>"; |
| 106 | |
| 107 | case TDE_APP_PREFIX . '-discounted-price': |
| 108 | if ( ! class_exists( 'WooCommerce' ) ) { |
| 109 | return ''; |
| 110 | } |
| 111 | $product_id = tutor_utils()->get_course_product_id( $course_id ); |
| 112 | $product = wc_get_product( $product_id ); |
| 113 | if ( ! $product ) { |
| 114 | return ''; |
| 115 | } |
| 116 | $sale_price = wc_price( $product->get_sale_price() ); |
| 117 | |
| 118 | if ( ! $sale_price ) { |
| 119 | return ''; |
| 120 | } |
| 121 | |
| 122 | return "<span $this->attributes>$sale_price</span>"; |
| 123 | |
| 124 | case TDE_APP_PREFIX . '-regular-price': |
| 125 | if ( ! class_exists( 'WooCommerce' ) ) { |
| 126 | return ''; |
| 127 | } |
| 128 | $product_id = tutor_utils()->get_course_product_id( $course_id ); |
| 129 | $product = wc_get_product( $product_id ); |
| 130 | if ( ! $product ) { |
| 131 | return ''; |
| 132 | } |
| 133 | $regular_price = wc_price( $product->get_regular_price() ); |
| 134 | |
| 135 | if ( ! $regular_price ) { |
| 136 | return ''; |
| 137 | } |
| 138 | |
| 139 | return "<span $this->attributes>$regular_price</span>"; |
| 140 | |
| 141 | case TDE_APP_PREFIX . '-course-action-buttons': |
| 142 | $is_course_completed = tutor_utils()->is_completed_course( $course_id, get_current_user_id() ); |
| 143 | if ( ( tutor_entry_box_buttons( $course_id )->show_start_learning_btn && ! $is_course_completed ) || ( tutor_entry_box_buttons( $course_id )->show_continue_learning_btn && ! $is_course_completed ) || tutor_entry_box_buttons( $course_id )->show_retake_course_btn || ( tutor_entry_box_buttons( $course_id )->show_certificate_view_btn && function_exists( 'TUTOR_CERT' ) ) ) { |
| 144 | return $this->generate_common_element(); |
| 145 | } else { |
| 146 | return ''; |
| 147 | } |
| 148 | |
| 149 | case TDE_APP_PREFIX . '-start-learning': |
| 150 | if ( ! tutor_entry_box_buttons( $course_id )->show_start_learning_btn ) { |
| 151 | return ''; |
| 152 | } |
| 153 | $is_course_completed = tutor_utils()->is_completed_course( $course_id, get_current_user_id() ); |
| 154 | if ( $is_course_completed ) { |
| 155 | return ''; |
| 156 | } |
| 157 | $lession_url = tutor_utils()->get_course_first_lesson(); |
| 158 | $children_html = $this->generate_child_elements(); |
| 159 | return "<a href='$lession_url' $this->attributes data-ele_name='$ele_name'>$children_html</a>"; |
| 160 | |
| 161 | case TDE_APP_PREFIX . '-continue-learning': |
| 162 | if ( ! tutor_entry_box_buttons( $course_id )->show_continue_learning_btn ) { |
| 163 | return ''; |
| 164 | } |
| 165 | $is_course_completed = tutor_utils()->is_completed_course( $course_id, get_current_user_id() ); |
| 166 | |
| 167 | if ( $is_course_completed ) { |
| 168 | return ''; |
| 169 | } |
| 170 | $lession_url = tutor_utils()->get_course_first_lesson(); |
| 171 | $children_html = $this->generate_child_elements(); |
| 172 | return "<a href='$lession_url' $this->attributes data-ele_name='$ele_name'>$children_html</a>"; |
| 173 | |
| 174 | case TDE_APP_PREFIX . '-complete-course': |
| 175 | if ( ! tutor_entry_box_buttons( $course_id )->show_complete_course_btn ) { |
| 176 | return ''; |
| 177 | } |
| 178 | $is_course_completed = tutor_utils()->is_completed_course( $course_id, get_current_user_id() ); |
| 179 | if ( $is_course_completed ) { |
| 180 | return ''; |
| 181 | } |
| 182 | |
| 183 | $children_html = $this->generate_child_elements(); |
| 184 | $children_html .= "<input type='hidden' name='course_id' value='$course_id' />"; |
| 185 | return "<button $this->attributes data-ele_name='$ele_name'>$children_html</button>"; |
| 186 | |
| 187 | case TDE_APP_PREFIX . '-retake-and-certificate': |
| 188 | if ( tutor_entry_box_buttons( $course_id )->show_retake_course_btn || ( tutor_entry_box_buttons( $course_id )->show_certificate_view_btn && function_exists( 'TUTOR_CERT' ) ) ) { |
| 189 | return $this->generate_common_element(); |
| 190 | } else { |
| 191 | return ''; |
| 192 | } |
| 193 | case TDE_APP_PREFIX . '-retake-course': |
| 194 | if ( ! tutor_entry_box_buttons( $course_id )->show_retake_course_btn ) { |
| 195 | return ''; |
| 196 | } |
| 197 | // TODO: Retake functionality |
| 198 | return $this->generate_common_element(); |
| 199 | |
| 200 | case TDE_APP_PREFIX . '-view-certificate': |
| 201 | if ( ! function_exists( 'TUTOR_CERT' ) ) { |
| 202 | return ''; |
| 203 | } |
| 204 | if ( ! tutor_entry_box_buttons( $course_id )->show_certificate_view_btn ) { |
| 205 | return ''; |
| 206 | } |
| 207 | $is_course_completed = tutor_utils()->is_completed_course( $course_id, get_current_user_id() ); |
| 208 | |
| 209 | if ( ! $is_course_completed ) { |
| 210 | return ''; |
| 211 | } |
| 212 | |
| 213 | $certificate_url = ''; |
| 214 | if ( tutils()->is_addon_enabled( TUTOR_CERT()->basename ) ) { |
| 215 | $certificate_url = ( new Certificate( true ) )->get_certificate( $course_id ); |
| 216 | } |
| 217 | $children_html = $this->generate_child_elements(); |
| 218 | return "<a href='$certificate_url' $this->attributes data-ele_name='$ele_name'>$children_html</a>"; |
| 219 | |
| 220 | case TDE_APP_PREFIX . '-enroll-info': |
| 221 | $is_enrolled = tutor_utils()->is_enrolled( $course_id ); |
| 222 | if ( ! $is_enrolled ) { |
| 223 | return ''; |
| 224 | } |
| 225 | return $this->generate_common_element(); |
| 226 | |
| 227 | case TDE_APP_PREFIX . '-enroll-date': |
| 228 | $is_enrolled = tutor_utils()->is_enrolled( $course_id ); |
| 229 | $post_date = is_object( $is_enrolled ) && isset( $is_enrolled->post_date ) ? $is_enrolled->post_date : ''; |
| 230 | $post_date = tutor_i18n_get_formated_date( $post_date, get_option( 'date_format' ) ); |
| 231 | return $this->generate_common_element( false, $post_date ); |
| 232 | |
| 233 | case TDE_APP_PREFIX . '-lesson-counter': |
| 234 | $course_progress = tutor_utils()->get_course_completed_percent( $course_id, 0, true ); |
| 235 | $html = $course_progress['completed_count'] . '/' . $course_progress['total_count']; |
| 236 | return $this->generate_common_element( false, $html ); |
| 237 | |
| 238 | case TDE_APP_PREFIX . '-progress-percent': |
| 239 | $course_progress = tutor_utils()->get_course_completed_percent( $course_id, 0, true ); |
| 240 | $completed_percent = $course_progress['completed_percent']; |
| 241 | $html = $completed_percent . '%'; |
| 242 | return $this->generate_common_element( false, $html ); |
| 243 | |
| 244 | case TDE_APP_PREFIX . '-progress-bar-inner': |
| 245 | $id = $this->element['id']; |
| 246 | $course_progress = tutor_utils()->get_course_completed_percent( $course_id, 0, true ); |
| 247 | $completed_percent = $course_progress['completed_percent']; |
| 248 | |
| 249 | $html = "<style>[data-droip='$id']{width: $completed_percent% !important;}</style>" . $this->generate_common_element( false ); |
| 250 | return $html; |
| 251 | default: |
| 252 | return ''; |
| 253 | } |
| 254 | } |
| 255 | } |