| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class LP_Profile_Template |
| 4 |
* |
| 5 |
* Group templates related user profile. |
| 6 |
* |
| 7 |
* @since 4.0.0 |
| 8 |
*/ |
| 9 |
class LP_Template_Profile extends LP_Abstract_Template { |
| 10 |
public function header( $user ) { |
| 11 |
$profile = LP_Global::profile(); |
| 12 |
|
| 13 |
if ( $profile->get_user()->is_guest() ) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
learn_press_get_template( 'profile/header.php', array( 'user' => $user ) ); |
| 18 |
} |
| 19 |
|
| 20 |
public function sidebar() { |
| 21 |
$profile = LP_Global::profile(); |
| 22 |
|
| 23 |
if ( $profile->get_user()->is_guest() ) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
learn_press_get_template( 'profile/sidebar.php' ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* @param LP_Profile $user |
| 32 |
*/ |
| 33 |
public function content( LP_Profile $user ) { |
| 34 |
$profile = LP_Global::profile(); |
| 35 |
$user_id = get_current_user_id(); |
| 36 |
|
| 37 |
if ( $profile->get_user()->is_guest() ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
$current_tab = $profile->get_current_tab(); |
| 42 |
|
| 43 |
if ( 'settings' === $current_tab && ( ! $user_id || $user_id != $profile->get_user()->get_id() ) ) { |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
$privacy = get_user_meta( $user->get_user()->get_id(), '_lp_profile_privacy', true ); |
| 48 |
|
| 49 |
if ( ! current_user_can( ADMIN_ROLE ) && ( $user->get_user()->get_id() != $user_id && empty( $privacy ) ) ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
$profile = learn_press_get_profile(); |
| 54 |
/** |
| 55 |
* LP_Profile_Tabs |
| 56 |
*/ |
| 57 |
$tabs = $profile->get_tabs(); |
| 58 |
$tab_key = $profile->get_current_tab(); |
| 59 |
$profile_tab = $tabs->get( $tab_key ); |
| 60 |
|
| 61 |
learn_press_get_template( 'profile/content.php', compact( 'user', 'profile_tab', 'tab_key', 'profile' ) ); |
| 62 |
} |
| 63 |
|
| 64 |
public function avatar() { |
| 65 |
learn_press_get_template( 'profile/avatar.php' ); |
| 66 |
} |
| 67 |
|
| 68 |
public function socials() { |
| 69 |
learn_press_get_template( 'profile/socials.php' ); |
| 70 |
} |
| 71 |
|
| 72 |
public function tabs( $user = null ) { |
| 73 |
$profile = LP_Global::profile(); |
| 74 |
|
| 75 |
if ( $profile->get_user()->is_guest() ) { |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
learn_press_get_template( 'profile/tabs.php', compact( 'user', 'profile' ) ); |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Get template tab course |
| 84 |
* |
| 85 |
* @author tungnx |
| 86 |
* @since 4.1.5 |
| 87 |
* @version 1.0.0 |
| 88 |
* @return void |
| 89 |
*/ |
| 90 |
public static function tab_courses() { |
| 91 |
if ( ! LP_Profile::instance()->current_user_can( 'view-tab-courses' ) ) { |
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
$user = LP_Profile::instance()->get_user(); |
| 96 |
|
| 97 |
$courses_enrolled_tab = apply_filters( |
| 98 |
'lp/profile/user_courses_attend/subtask', |
| 99 |
array( |
| 100 |
'' => esc_html__( 'All', 'learnpress' ), |
| 101 |
'in-progress' => esc_html__( 'In Progress', 'learnpress' ), |
| 102 |
'finished' => esc_html__( 'Finished', 'learnpress' ), |
| 103 |
'passed' => esc_html__( 'Passed', 'learnpress' ), |
| 104 |
'failed' => esc_html__( 'Failed', 'learnpress' ), |
| 105 |
) |
| 106 |
); |
| 107 |
|
| 108 |
$courses_created_tab = apply_filters( |
| 109 |
'lp/profile/user_courses_created/subtask', |
| 110 |
array( |
| 111 |
'' => esc_html__( 'All', 'learnpress' ), |
| 112 |
'publish' => esc_html__( 'Publish', 'learnpress' ), |
| 113 |
'pending' => esc_html__( 'Pending', 'learnpress' ), |
| 114 |
) |
| 115 |
); |
| 116 |
|
| 117 |
$courses_enrolled_tab_active = apply_filters( 'learnpress/profile/tab/enrolled/subtab-active', ! learn_press_user_maybe_is_a_teacher() ? 'in-progress' : '' ); |
| 118 |
$tab_active = LP_Helper::sanitize_params_submitted( $_GET['tab'] ?? '' ); |
| 119 |
if ( ! $tab_active ) { |
| 120 |
$tab_active = ! learn_press_user_maybe_is_a_teacher() ? 'enrolled' : 'created'; |
| 121 |
} |
| 122 |
$tab_active = apply_filters( 'learnpress/profile/tab-active', $tab_active ); |
| 123 |
|
| 124 |
$args_query_user_courses_created = apply_filters( |
| 125 |
'lp/profile/args/user_courses_created', |
| 126 |
array( |
| 127 |
'userID' => $user->get_id(), |
| 128 |
'query' => 'own', |
| 129 |
) |
| 130 |
); |
| 131 |
$args_query_user_courses_attend = apply_filters( |
| 132 |
'lp/profile/args/user_courses_attend', |
| 133 |
array( |
| 134 |
'userID' => $user->get_id(), |
| 135 |
'query' => 'purchased', |
| 136 |
'layout' => 'list', |
| 137 |
) |
| 138 |
); |
| 139 |
$args_query_user_courses_statistic = apply_filters( |
| 140 |
'lp/profile/args/user_courses_statistic', |
| 141 |
array( |
| 142 |
'userID' => $user->get_id(), |
| 143 |
) |
| 144 |
); |
| 145 |
|
| 146 |
learn_press_get_template( |
| 147 |
'profile/tabs/courses', |
| 148 |
compact( |
| 149 |
'user', |
| 150 |
'courses_created_tab', |
| 151 |
'courses_enrolled_tab', |
| 152 |
'tab_active', |
| 153 |
'courses_enrolled_tab_active', |
| 154 |
'args_query_user_courses_attend', |
| 155 |
'args_query_user_courses_created', |
| 156 |
'args_query_user_courses_statistic' |
| 157 |
) |
| 158 |
); |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* @author tungnx |
| 163 |
* @deprecated 4.1.6 |
| 164 |
*/ |
| 165 |
/*public function dashboard_statistic() { |
| 166 |
$user = $this->get_user(); |
| 167 |
$query = LP_Profile::instance()->query_courses( 'purchased' ); |
| 168 |
$counts = $query['counts']; |
| 169 |
$statistic = array( |
| 170 |
'enrolled_courses' => isset( $counts['all'] ) ? $counts['all'] : 0, |
| 171 |
'active_courses' => isset( $counts['in-progress'] ) ? $counts['in-progress'] : 0, |
| 172 |
'completed_courses' => isset( $counts['finished'] ) ? $counts['finished'] : 0, |
| 173 |
'total_courses' => count_user_posts( $user->get_id(), LP_COURSE_CPT ), |
| 174 |
'total_users' => learn_press_count_instructor_users( $user->get_id() ), |
| 175 |
); |
| 176 |
|
| 177 |
learn_press_get_template( 'profile/tabs/courses/general-statistic', compact( 'statistic' ) ); |
| 178 |
}*/ |
| 179 |
|
| 180 |
public function dashboard_featured_courses() { |
| 181 |
$profile_privacy = $this->get_user()->get_extra_data( |
| 182 |
'profile_privacy', |
| 183 |
array( |
| 184 |
'courses' => 'no', |
| 185 |
'quizzes' => 'no', |
| 186 |
) |
| 187 |
); |
| 188 |
|
| 189 |
if ( $this->get_user()->get_id() !== get_current_user_id() && 'yes' !== $profile_privacy['courses'] ) { |
| 190 |
return; |
| 191 |
} |
| 192 |
|
| 193 |
$user = $this->get_user(); |
| 194 |
$query = new LP_Course_Query( |
| 195 |
array( |
| 196 |
'paginate' => true, |
| 197 |
'featured' => 'yes', |
| 198 |
'return' => 'ids', |
| 199 |
'author' => $user->get_id(), |
| 200 |
) |
| 201 |
); |
| 202 |
|
| 203 |
$data = $query->get_courses(); |
| 204 |
|
| 205 |
learn_press_get_template( 'profile/dashboard/featured-courses', (array) $data ); |
| 206 |
} |
| 207 |
|
| 208 |
public function dashboard_latest_courses() { |
| 209 |
$profile_privacy = $this->get_user()->get_extra_data( |
| 210 |
'profile_privacy', |
| 211 |
array( |
| 212 |
'courses' => 'no', |
| 213 |
'quizzes' => 'no', |
| 214 |
) |
| 215 |
); |
| 216 |
|
| 217 |
if ( $this->get_user()->get_id() !== get_current_user_id() && 'yes' !== $profile_privacy['courses'] ) { |
| 218 |
return; |
| 219 |
} |
| 220 |
|
| 221 |
$user = $this->get_user(); |
| 222 |
$query = new LP_Course_Query( |
| 223 |
array( |
| 224 |
'paginate' => true, |
| 225 |
'return' => 'ids', |
| 226 |
'author' => $user->get_id(), |
| 227 |
) |
| 228 |
); |
| 229 |
|
| 230 |
learn_press_get_template( 'profile/dashboard/latest-courses', (array) $query->get_courses() ); |
| 231 |
} |
| 232 |
|
| 233 |
public function order_details() { |
| 234 |
$profile = LP_Profile::instance(); |
| 235 |
|
| 236 |
$order = $profile->get_view_order(); |
| 237 |
|
| 238 |
if ( false === $order ) { |
| 239 |
return; |
| 240 |
} |
| 241 |
|
| 242 |
learn_press_get_template( 'order/order-details.php', array( 'order' => $order ) ); |
| 243 |
} |
| 244 |
|
| 245 |
public function order_recover() { |
| 246 |
$profile = LP_Profile::instance(); |
| 247 |
$order = $profile->get_view_order(); |
| 248 |
|
| 249 |
if ( false === $order ) { |
| 250 |
return; |
| 251 |
} |
| 252 |
|
| 253 |
//learn_press_get_template( 'profile/tabs/orders/recover-my-order.php', array( 'order' => $order ) ); |
| 254 |
} |
| 255 |
|
| 256 |
public function order_message() { |
| 257 |
$profile = LP_Profile::instance(); |
| 258 |
$order = $profile->get_view_order(); |
| 259 |
|
| 260 |
if ( false === $order ) { |
| 261 |
return; |
| 262 |
} |
| 263 |
|
| 264 |
learn_press_get_template( 'profile/tabs/orders/order-message.php', array( 'order' => $order ) ); |
| 265 |
} |
| 266 |
|
| 267 |
public function dashboard_not_logged_in() { |
| 268 |
$profile = LP_Global::profile(); |
| 269 |
|
| 270 |
if ( ! $profile->get_user()->is_guest() ) { |
| 271 |
return; |
| 272 |
} |
| 273 |
|
| 274 |
if ( 'yes' === LP_Settings::instance()->get( 'enable_login_profile' ) || 'yes' === LP_Settings::instance()->get( 'enable_register_profile' ) ) { |
| 275 |
return; |
| 276 |
} |
| 277 |
|
| 278 |
learn_press_get_template( 'profile/not-logged-in.php' ); |
| 279 |
} |
| 280 |
|
| 281 |
public function login_form() { |
| 282 |
$profile = LP_Global::profile(); |
| 283 |
|
| 284 |
if ( ! $profile->get_user()->is_guest() ) { |
| 285 |
return; |
| 286 |
} |
| 287 |
|
| 288 |
if ( 'yes' !== LP_Settings::instance()->get( 'enable_login_profile' ) ) { |
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
learn_press_get_template( 'global/form-login.php' ); |
| 293 |
} |
| 294 |
|
| 295 |
public function register_form() { |
| 296 |
$profile = LP_Global::profile(); |
| 297 |
|
| 298 |
if ( ! $profile->get_user()->is_guest() ) { |
| 299 |
return; |
| 300 |
} |
| 301 |
|
| 302 |
if ( 'yes' !== LP_Settings::instance()->get( 'enable_register_profile' ) || ! get_option( 'users_can_register' ) ) { |
| 303 |
return; |
| 304 |
} |
| 305 |
|
| 306 |
learn_press_get_template( 'global/form-register.php' ); |
| 307 |
} |
| 308 |
|
| 309 |
/** |
| 310 |
* @return bool|LP_User|mixed |
| 311 |
*/ |
| 312 |
protected function get_user() { |
| 313 |
return LP_Profile::instance()->get_user(); |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
return new LP_Template_Profile(); |
| 318 |
|