/** * Gets quiz questions * * @access public * @param int $ID * @return array */ public static function getQuestions($ID) { $selection = absint(ThemexCore::getPostMeta($ID, 'quiz_selection')); $questions = themex_filter(ThemexCore::getPostMeta($ID, 'quiz_questions')); if (!empty($selection) && $selection < count($questions)) { $keys = ThemexCore::getUserRelations(get_current_user_id(), $ID, 'questions', true); if (!empty($keys)) { $keys = explode(',', $keys); $questions = array_intersect_key($questions, array_flip($keys)); } if ($selection != count($questions)) { $questions = themex_shuffle($questions); $questions = array_slice($questions, 0, $selection); $keys = implode(',', array_keys($questions)); ThemexCore::addUserRelation(get_current_user_id(), $ID, 'questions', $keys); } } return $questions; }
/** * Adds course member * * @access public * @param int $ID * @param bool $private * @return void */ public static function addUser($ID, $user, $private = false) { self::refresh($ID); $redirect = get_permalink($ID); if ($user != 0 || self::$data['status'] == 'premium' && self::$data['product'] != 0) { if (!self::isMember($user)) { if ($private || self::$data['status'] == 'free' || self::$data['status'] == 'premium' && self::$data['product'] == 0) { ThemexCore::addUserRelation($user, $ID, 'course', current_time('timestamp')); self::$data['users'][] = $user; $number = count(self::$data['users']); ThemexCore::updatePostMeta($ID, 'course_popularity', $number); $message = ThemexCore::getOption('email_course'); if (!empty($message)) { $data = get_userdata($user); $keywords = array('username' => $data->user_login, 'title' => get_the_title($ID), 'link' => $redirect); themex_mail($data->user_email, __('Course Membership', 'academy'), themex_keywords($message, $keywords)); } if (!$private) { wp_redirect($redirect); exit; } } else { if (self::$data['status'] == 'premium') { ThemexWoo::addProduct(self::$data['product']); } } } else { if (!$private) { wp_redirect($redirect); exit; } } } }
/** * Adds user relation * * @access public * @param int $ID * @param array $data * @return void */ public static function addRelation($ID, $data) { $relation = themex_value('relation_id', $data); $type = themex_value('relation_type', $data); if (in_array($type, array('shop', 'product'))) { ThemexCore::addUserRelation($ID, $relation, $type); if ($type == 'shop') { $relations = count(ThemexCore::getUserRelations(0, $relation, 'shop')); ThemexCore::updatePostMeta($relation, 'admirers', $relations); } } die; }