lib/model/WpProQuiz_Model_Statistic.php 0000666 00000005750 15214236625 0014233 0 ustar 00 _statisticRefId = (int)$_statisticRefId; return $this; } public function getStatisticRefId() { return $this->_statisticRefId; } public function setQuestionId($_questionId) { $this->_questionId = (int)$_questionId; return $this; } public function getQuestionId() { return $this->_questionId; } public function setCorrectCount($_correctCount) { $this->_correctCount = (int)$_correctCount; return $this; } public function getCorrectCount() { return $this->_correctCount; } public function setIncorrectCount($_incorrectCount) { $this->_incorrectCount = (int)$_incorrectCount; return $this; } public function getIncorrectCount() { return $this->_incorrectCount; } public function setHintCount($_hintCount) { $this->_hintCount = (int)$_hintCount; return $this; } public function getHintCount() { return $this->_hintCount; } public function setPoints($_points) { $this->_points = (int)$_points; return $this; } public function getPoints() { return $this->_points; } public function setQuestionTime($_questionTime) { $this->_questionTime = (int)$_questionTime; return $this; } public function getQuestionTime() { return $this->_questionTime; } public function setAnswerData($_answerData) { $this->_answerData = $_answerData; return $this; } public function getAnswerData() { return $this->_answerData; } public function get_object_as_array() { $object_vars = array( '_statisticRefId' => $this->getStatisticRefId(), '_questionId' => $this->getQuestionId(), '_correctCount' => $this->getCorrectCount(), '_incorrectCount' => $this->getIncorrectCount(), '_hintCount' => $this->getHintCount(), '_points' => $this->getPoints(), '_questionTime' => $this->getQuestionTime(), '_answerData' => $this->getAnswerData() ); return $object_vars; } public function set_array_to_object( $array_vars = array() ) { foreach( $array_vars as $key => $value ) { switch( $key ) { case '_statisticRefId': $this->setStatisticRefId( $value ); break; case '_questionId': $this->setQuestionId( $value ); break; case '_correctCount': $this->setCorrectCount( $value ); break; case '_incorrectCount': $this->setIncorrectCount( $value ); break; case '_hintCount': $this->setHintCount( $value ); break; case '_points': $this->setPoints( $value ); break; case '_questionTime': $this->setQuestionTime( $value ); break; case '_answerData': $this->setAnswerData( $value ); } } } } lib/model/WpProQuiz_Model_GlobalSettingsMapper.php 0000666 00000010557 15214236625 0016353 0 ustar 00 setAddRawShortcode( $wpProQuiz_addRawShortcode ) ->setJsLoadInHead( $wpProQuiz_jsLoadInHead ) ->setTouchLibraryDeactivate( $wpProQuiz_touchLibraryDeactivate ) ->setCorsActivated( $wpProQuiz_corsActivated ); return $s; } public function save(WpProQuiz_Model_GlobalSettings $settings) { if(add_option('wpProQuiz_addRawShortcode', $settings->isAddRawShortcode()) === false) { update_option('wpProQuiz_addRawShortcode', $settings->isAddRawShortcode()); } if(add_option('wpProQuiz_jsLoadInHead', $settings->isJsLoadInHead()) === false) { update_option('wpProQuiz_jsLoadInHead', $settings->isJsLoadInHead()); } if(add_option('wpProQuiz_touchLibraryDeactivate', $settings->isTouchLibraryDeactivate()) === false) { update_option('wpProQuiz_touchLibraryDeactivate', $settings->isTouchLibraryDeactivate()); } if(add_option('wpProQuiz_corsActivated', $settings->isCorsActivated()) === false) { update_option('wpProQuiz_corsActivated', $settings->isCorsActivated()); } } public function delete() { delete_option('wpProQuiz_addRawShortcode'); delete_option('wpProQuiz_jsLoadInHead'); delete_option('wpProQuiz_touchLibraryDeactivate'); delete_option('wpProQuiz_corsActivated'); } public function getEmailSettings() { $e = get_option('wpProQuiz_emailSettings', null); if($e === null) { $e['to'] = ''; $e['from'] = ''; $e['subject'] = sprintf( esc_html_x('LearnDash %1$s: One user completed a %2$s', 'LearnDash Quiz: One user completed a quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ), learndash_get_custom_label_lower( 'quiz' ) ); $e['html'] = false; $e['message'] = sprintf( esc_html_x('LearnDash %s The user "$username" has completed "$quizname" the %s. Points: $points Result: $result ', 'placeholders: Quiz, quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ), learndash_get_custom_label_lower( 'quiz' )); } return $e; } public function saveEmailSettiongs($data) { if(isset($data['html']) && $data['html']) $data['html'] = true; else $data['html'] = false; if(add_option('wpProQuiz_emailSettings', $data, '', 'no') === false) { update_option('wpProQuiz_emailSettings', $data); } } public function getUserEmailSettings() { $e = get_option('wpProQuiz_userEmailSettings', null); if($e === null) { $e['from'] = ''; $e['subject'] = sprintf( esc_html_x('LearnDash %1$s: One user completed a %2$s', 'LearnDash Quiz: One user completed a quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ), learndash_get_custom_label_lower( 'quiz' ) ); $e['html'] = false; $e['message'] = sprintf( esc_html_x('LearnDash %s You have completed the %s "$quizname". Points: $points Result: $result ', 'placeholders: Quiz, quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ), learndash_get_custom_label_lower( 'quiz' ) ); } return $e; } public function saveUserEmailSettiongs($data) { if(isset($data['html']) && $data['html']) $data['html'] = true; else $data['html'] = false; if(add_option('wpProQuiz_userEmailSettings', $data, '', 'no') === false) { update_option('wpProQuiz_userEmailSettings', $data); } } } lib/model/WpProQuiz_Model_QuestionMapper.php 0000666 00000030264 15214236625 0015236 0 ustar 00 _table = $this->_prefix."question"; $this->_table = $this->_tableQuestion; } public function delete($id) { $this->_wpdb->delete($this->_table, array('id' => $id), '%d'); } public function deleteByQuizId($id) { $this->_wpdb->delete($this->_table, array('quiz_id' => $id), '%d'); } public function getSort($questionId) { return $this->_wpdb->get_var($this->_wpdb->prepare("SELECT sort FROM {$this->_tableQuestion} WHERE id = %d", $questionId)); } public function updateSort($id, $sort) { $this->_wpdb->update( $this->_table, array( 'sort' => $sort), array('id' => $id), array('%d'), array('%d') ); if ( true === is_data_upgrade_quiz_questions_updated() ) { $question_post_id = learndash_get_question_post_by_pro_id( $id ); if ( ! empty( $question_post_id ) ) { $update_post = array( 'ID' => $question_post_id, 'menu_order' => absint( $sort ), ); wp_update_post( $update_post ); learndash_set_question_quizzes_dirty( $question_post_id ); } } } public function setOnlineOff($questionId) { return $this->_wpdb->update($this->_tableQuestion, array('online' => 0), array('id' => $questionId), null, array('%d')); } public function getQuizId($questionId) { return $this->_wpdb->get_var($this->_wpdb->prepare("SELECT quiz_id FROM {$this->_tableQuestion} WHERE id = %d", $questionId)); } public function getMaxSort($quizId) { return $this->_wpdb->get_var($this->_wpdb->prepare( "SELECT MAX(sort) AS max_sort FROM {$this->_tableQuestion} WHERE quiz_id = %d AND online = 1", $quizId)); } public function save(WpProQuiz_Model_Question $question, $auto = false) { $sort = null; if($auto && $question->getId()) { $statisticMapper = new WpProQuiz_Model_StatisticMapper(); if($statisticMapper->isStatisticByQuestionId($question->getId())) { $this->setOnlineOff($question->getId()); $question->setQuizId($this->getQuizId($question->getId())); $question->setId(0); $sort = $question->getSort(); } } /** * Convert emoji to HTML entities to allow saving in DB. * * @since 2.6.0. */ $question_title = $question->getTitle(); $question_title = wp_encode_emoji( $question_title ); $question_question = $question->getQuestion(); $question_question = wp_encode_emoji( $question_question ); if($question->getId() != 0) { $this->_wpdb->update( $this->_table, array( 'quiz_id' => $question->getQuizId(), 'title' => $question_title, 'points' => $question->getPoints(), 'question' => $question_question, 'correct_msg' => $question->getCorrectMsg(), 'incorrect_msg' => $question->getIncorrectMsg(), 'correct_same_text' => (int)$question->isCorrectSameText(), 'tip_enabled' => (int)$question->isTipEnabled(), 'tip_msg' => $question->getTipMsg(), 'answer_type' => $question->getAnswerType(), 'show_points_in_box' => (int)$question->isShowPointsInBox(), 'answer_points_activated' => (int)$question->isAnswerPointsActivated(), 'answer_data' => $question->getAnswerData(true), 'category_id' => $question->getCategoryId(), 'answer_points_diff_modus_activated' => (int)$question->isAnswerPointsDiffModusActivated(), 'disable_correct' => (int)$question->isDisableCorrect(), 'matrix_sort_answer_criteria_width' => $question->getMatrixSortAnswerCriteriaWidth() ), array('id' => $question->getId()), array('%s', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%d'), array('%d')); } else { $this->_wpdb->insert($this->_table, array( 'quiz_id' => $question->getQuizId(), 'online' => 1, 'sort' => $sort !== null ? $sort : ($this->getMaxSort($question->getQuizId()) + 1), 'title' => $question_title, 'points' => $question->getPoints(), 'question' => $question_question, 'correct_msg' => $question->getCorrectMsg(), 'incorrect_msg' => $question->getIncorrectMsg(), 'correct_same_text' => (int)$question->isCorrectSameText(), 'tip_enabled' => (int)$question->isTipEnabled(), 'tip_msg' => $question->getTipMsg(), 'answer_type' => $question->getAnswerType(), 'show_points_in_box' => (int)$question->isShowPointsInBox(), 'answer_points_activated' => (int)$question->isAnswerPointsActivated(), 'answer_data' => $question->getAnswerData(true), 'category_id' => $question->getCategoryId(), 'answer_points_diff_modus_activated' => (int)$question->isAnswerPointsDiffModusActivated(), 'disable_correct' => (int)$question->isDisableCorrect(), 'matrix_sort_answer_criteria_width' => $question->getMatrixSortAnswerCriteriaWidth() ), array('%d', '%d', '%d', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%s', '%s', '%d', '%d', '%s', '%d', '%d', '%d', '%d') ); $question->setId($this->_wpdb->insert_id); } if ( ( true === is_data_upgrade_quiz_questions_updated() ) && ( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Builder', 'enabled' ) !== 'yes' ) ) { $question_post_id = learndash_get_question_post_by_pro_id( $question->getId() ); if ( empty( $question_post_id ) ) { // We load fresh from DB. Don't use the $question object as it is not up to date. $question_pro = $this->fetchById( $question->getId() ); if ( ( $question_pro ) && ( is_a( $question_pro, 'WpProQuiz_Model_Question' ) ) ) { $question_insert_post = array(); $question_insert_post['post_type'] = learndash_get_post_type_slug( 'question' ); $question_insert_post['post_status'] = 'publish'; $question_insert_post['post_title'] = $question_pro->getTitle(); $question_insert_post['post_content'] = $question_pro->getQuestion(); $question_insert_post['menu_order'] = absint( $question_pro->getSort() ); $question_insert_post = wp_slash( $question_insert_post ); $question_insert_post_id = wp_insert_post( $question_insert_post ); if ( false !== $question_insert_post_id ) { $quiz_pro_id = $question_pro->getQuizId(); $quiz_pro_id = absint( $quiz_pro_id ); $quiz_post_id = learndash_get_quiz_id_by_pro_quiz_id( $quiz_pro_id ); learndash_update_setting( $question_insert_post_id, 'quiz', $quiz_post_id ); learndash_proquiz_sync_question_fields( $question_insert_post_id, $question_pro ); learndash_set_question_quizzes_dirty( $question_insert_post_id ); } } } } return $question; } public function fetch($id) { $row = $this->_wpdb->get_row( $this->_wpdb->prepare( "SELECT * FROM ". $this->_table. " WHERE id = %d AND online = 1", $id), ARRAY_A ); $model = new WpProQuiz_Model_Question($row); return $model; } public function fetchById($id, $online = 1 ) { $ids = array_map('intval', (array)$id); $a = array(); if(empty($ids)) return null; $sql_str = "SELECT * FROM ". $this->_table. " WHERE id IN(". implode(', ', $ids) .") "; if ( ( $online === 1 ) || ( $online === 1 ) ) { $sql_str .= " AND online = ". $online; } $results = $this->_wpdb->get_results( $sql_str, ARRAY_A ); foreach ($results as $row) { $a[] = new WpProQuiz_Model_Question($row); } return is_array($id) ? $a : (isset($a[0]) ? $a[0] : null); } public function fetchAll( $quizId = 0, $rand = false, $max = 0 ) { $quiz_post_id = 0; if ( is_a( $quizId, 'WpProQuiz_Model_Quiz' ) ) { $quiz = $quizId; $quizId = $quiz->getId(); if ( empty( $quiz_post_id ) ) { $quiz_post_id = $quiz->getPostId(); } } else { $quiz_post_id = learndash_get_question_post_by_pro_id( $quizId ); if ( empty( $quiz_post_id ) ) { if ( ( isset( $_GET['post'] ) ) && ( ! empty( $_GET['post'] ) ) ) { $quiz_post_id = learndash_get_quiz_id( absint( $_GET['post'] ) ); } } } if ( ( ! empty( $quiz_post_id ) ) && ( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Builder', 'enabled' ) === 'yes' ) && ( true === is_data_upgrade_quiz_questions_updated() ) ) { $ld_quiz_questions_object = LDLMS_Factory_Post::quiz_questions( intval( $quiz_post_id ) ); if ( $ld_quiz_questions_object ) { $pro_questions = $ld_quiz_questions_object->get_questions( 'pro_objects' ); $pro_questions = apply_filters( 'learndash_fetch_quiz_questions', $pro_questions, $quizId, $rand, $max ); if ( ! empty( $pro_questions ) ) { if ( $rand ) { //$pro_questions = array_rand( $pro_questions, intval( $max ) ); shuffle( $pro_questions ); $max = absint( $max ); if ( $max > 0 ) { $pro_questions = array_slice( $pro_questions, 0, $max, true ); } } } if ( ! empty( $pro_questions ) ) { $category_mapper = new WpProQuiz_Model_CategoryMapper(); foreach( $pro_questions as $pro_question ) { $q_catId = $pro_question->getCategoryId(); $q_catId = absint( $q_catId ); if ( ! empty( $q_catId ) ) { $q_cat = $category_mapper->fetchById( $q_catId ); if ( ( $q_cat ) && ( is_a( $q_cat, 'WpProQuiz_Model_Category' ) ) ) { $_catName = $q_cat->getCategoryName(); if ( ! empty( $_catName ) ) { $pro_question->setCategoryName( $_catName ); } } } } } return $pro_questions; } } else { if ( $rand ) { $orderBy = 'ORDER BY RAND()'; } else { $orderBy = 'ORDER BY sort ASC'; } $limit = ''; if($max > 0) { $limit = 'LIMIT 0, '.((int)$max); } $a = array(); $results = $this->_wpdb->get_results( $this->_wpdb->prepare( 'SELECT q.*, c.category_name FROM '. $this->_table.' AS q LEFT JOIN '.$this->_tableCategory.' AS c ON c.category_id = q.category_id WHERE quiz_id = %d AND q.online = 1 '.$orderBy.' '.$limit , $quizId), ARRAY_A); foreach($results as $row) { $model = new WpProQuiz_Model_Question($row); $a[] = $model; } } return $a; } public function fetchAllList($quizId, $list) { $quiz_post_id = 0; if ( is_a( $quizId, 'WpProQuiz_Model_Quiz' ) ) { $quiz = $quizId; $quizId = $quiz->getId(); $quiz_post_id = $quiz->getPostId(); } if ( ( ! empty( $quiz_post_id ) ) && ( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Builder', 'enabled' ) === 'yes' ) && ( true === is_data_upgrade_quiz_questions_updated() ) ) { $ld_quiz_questions_object = LDLMS_Factory_Post::quiz_questions( intval( $quiz_post_id ) ); if ( $ld_quiz_questions_object ) { $questions = $ld_quiz_questions_object->get_questions(); if ( ! empty( $questions ) ) { $sql_str = "SELECT " . implode(', ', (array) $list ) . " FROM " . $this->_tableQuestion . " WHERE id IN (". implode(',', $questions) . ") AND online = 1"; $results = $this->_wpdb->get_results( $sql_str, ARRAY_A ); return $results; } } } else { $results = $this->_wpdb->get_results( $this->_wpdb->prepare( 'SELECT '.implode(', ', (array)$list).' FROM '. $this->_tableQuestion.' WHERE quiz_id = %d AND online = 1' , $quizId), ARRAY_A); return $results; } } public function count($quizId) { return $this->_wpdb->get_var($this->_wpdb->prepare("SELECT COUNT(*) FROM {$this->_table} WHERE quiz_id = %d AND online = 1", $quizId)); } public function exists($id) { return $this->_wpdb->get_var($this->_wpdb->prepare("SELECT COUNT(*) FROM {$this->_table} WHERE id = %d AND online = 1", $id)); } public function existsAndWritable($id) { return $this->_wpdb->get_var($this->_wpdb->prepare("SELECT COUNT(*) FROM {$this->_table} WHERE id = %d AND online = 1", $id)); } public function fetchCategoryPoints($quizId) { $results = $this->_wpdb->get_results( $this->_wpdb->prepare( 'SELECT SUM( points ) AS sum_points , category_id FROM '.$this->_tableQuestion.' WHERE quiz_id = %d AND online = 1 GROUP BY category_id', $quizId)); $a = array(); foreach($results as $result) { $a[$result['category_id']] = $result['sum_points']; } return $a; } } lib/model/WpProQuiz_Model_StatisticFormOverview.php 0000666 00000003277 15214236625 0016610 0 ustar 00 _userId = (int)$_userId; return $this; } public function getUserId() { return $this->_userId; } public function setUserName($_userName) { $this->_userName = (string)$_userName; return $this; } public function getUserName() { return $this->_userName; } public function setStatisticRefId($_statisticRefId) { $this->_statisticRefId = (int)$_statisticRefId; return $this; } public function getStatisticRefId() { return $this->_statisticRefId; } public function setQuizId($_quizId) { $this->_quizId = (int)$_quizId; return $this; } public function getQuizId() { return $this->_quizId; } public function setCreateTime($_createTime) { $this->_createTime = (int)$_createTime; return $this; } public function getCreateTime() { return $this->_createTime; } public function setCorrectCount($_correctCount) { $this->_correctCount = (int)$_correctCount; return $this; } public function getCorrectCount() { return $this->_correctCount; } public function setIncorrectCount($_incorrectCount) { $this->_incorrectCount = (int)$_incorrectCount; return $this; } public function getIncorrectCount() { return $this->_incorrectCount; } public function setPoints($_points) { $this->_points = (int)$_points; return $this; } public function getPoints() { return $this->_points; } } lib/model/WpProQuiz_Model_QuizMapper.php 0000666 00000021427 15214236625 0014360 0 ustar 00 _table = $this->_prefix."master"; $this->_table = $this->_tableMaster; } public function delete($id) { $this->_wpdb->delete($this->_table, array( 'id' => $id), array('%d')); } public function exists($id) { return $this->_wpdb->get_var($this->_wpdb->prepare("SELECT COUNT(*) FROM {$this->_table} WHERE id = %d", $id)); } public function fetch($id) { $queried_object = get_queried_object(); $sql_str = $this->_wpdb->prepare("SELECT * FROM {$this->_table} WHERE id = %d", $id ); $results = $this->_wpdb->get_row( $sql_str, ARRAY_A ); if($results['result_grade_enabled']) $results['result_text'] = unserialize($results['result_text']); return new WpProQuiz_Model_Quiz($results); } public function fetchAll() { $r = array(); $results = $this->_wpdb->get_results("SELECT * FROM {$this->_table} ORDER BY id ASC", ARRAY_A); foreach ($results as $row) { if($row['result_grade_enabled']) $row['result_text'] = unserialize($row['result_text']); $r[] = new WpProQuiz_Model_Quiz($row); } return $r; } public function save(WpProQuiz_Model_Quiz $data) { if($data->isResultGradeEnabled()) { $resultText = serialize($data->getResultText()); } else { $resultText = $data->getResultText(); } $name = $data->getName(); if(empty($name)) $name = "no title"; $text = $data->getText(); if(empty($text)) $text = "AAZZAAZZ"; $set = array( 'name' => $name, 'text' => $text, 'result_text' => $resultText, 'title_hidden' => (int)$data->isTitleHidden(), 'btn_restart_quiz_hidden' => (int)$data->isBtnRestartQuizHidden(), 'btn_view_question_hidden' => (int)$data->isBtnViewQuestionHidden(), 'question_random' => (int)$data->isQuestionRandom(), 'answer_random' => (int)$data->isAnswerRandom(), 'time_limit' => (int)$data->getTimeLimit(), 'statistics_on' => (int)$data->isStatisticsOn(), 'statistics_ip_lock' => (int)$data->getStatisticsIpLock(), 'result_grade_enabled' => (int)$data->isResultGradeEnabled(), 'show_points' => (int)$data->isShowPoints(), 'quiz_run_once' => (int)$data->isQuizRunOnce(), 'quiz_run_once_type' => $data->getQuizRunOnceType(), 'quiz_run_once_cookie' => (int)$data->isQuizRunOnceCookie(), 'quiz_run_once_time' => (int)$data->getQuizRunOnceTime(), 'numbered_answer' => (int)$data->isNumberedAnswer(), 'hide_answer_message_box' => (int)$data->isHideAnswerMessageBox(), 'disabled_answer_mark' => (int)$data->isDisabledAnswerMark(), 'show_max_question' => (int)$data->isShowMaxQuestion(), 'show_max_question_value' => (int)$data->getShowMaxQuestionValue(), 'show_max_question_percent' => (int)$data->isShowMaxQuestionPercent(), 'toplist_activated' => (int)$data->isToplistActivated(), 'toplist_data' => $data->getToplistData(), 'show_average_result' => (int)$data->isShowAverageResult(), 'prerequisite' => (int)$data->isPrerequisite(), 'quiz_modus' => (int)$data->getQuizModus(), 'show_review_question' => (int)$data->isShowReviewQuestion(), 'quiz_summary_hide' => (int)$data->isQuizSummaryHide(), 'skip_question_disabled' => (int)$data->isSkipQuestionDisabled(), 'email_notification' => $data->getEmailNotification(), 'user_email_notification' => (int)$data->isUserEmailNotification(), 'show_category_score' => (int)$data->isShowCategoryScore(), 'hide_result_correct_question' => (int)$data->isHideResultCorrectQuestion(), 'hide_result_quiz_time' => (int)$data->isHideResultQuizTime(), 'hide_result_points' => (int)$data->isHideResultPoints(), 'autostart' => (int)$data->isAutostart(), 'forcing_question_solve' => (int)$data->isForcingQuestionSolve(), 'hide_question_position_overview' => (int)$data->isHideQuestionPositionOverview(), 'hide_question_numbering' => (int)$data->isHideQuestionNumbering(), 'form_activated' => (int)$data->isFormActivated(), 'form_show_position' => $data->getFormShowPosition(), 'start_only_registered_user' => (int)$data->isStartOnlyRegisteredUser(), 'questions_per_page' => $data->getQuestionsPerPage(), 'sort_categories' => (int)$data->isSortCategories(), 'show_category' => (int)$data->isShowCategory() ); /** * Convert emoji to HTML entities to allow saving in DB. * * @since 2.6.0. */ $set['name'] = wp_encode_emoji( $set['name'] ); if($data->getId() != 0) { $result = $this->_wpdb->update( $this->_table, $set, array( 'id' => $data->getId() ), array( '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d' ), array( '%d' ) ); } else { $result = $this->_wpdb->insert( $this->_table, $set, array( '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d' ) ); $data->setId($this->_wpdb->insert_id); } if($result === false) { return null; } $data->saveTimeLimitCookie(); $data->saveViewProfileStatistics(); return $data; } public function sumQuestionPoints($id) { return $this->_wpdb->get_var($this->_wpdb->prepare("SELECT SUM(points) FROM {$this->_tableQuestion} WHERE quiz_id = %d AND online = 1", $id)); } public function sumQuestionPointsFromArray( $question_ids = array() ) { if ( ! empty( $question_ids ) ) { $sql_str = "SELECT SUM(points) FROM {$this->_tableQuestion} WHERE id IN (" . implode(',', $question_ids ) . ") AND online = 1"; return $this->_wpdb->get_var( $sql_str ); } else { return 0; } } public function countQuestion($id) { return $this->_wpdb->get_var($this->_wpdb->prepare("SELECT COUNT(*) FROM {$this->_tableQuestion} WHERE quiz_id = %d AND online = 1", $id)); } public function fetchAllAsArray( $list, $outIds = array() ) { $where = ' 1 '; if( !empty ($outIds ) ) { $where .= ' AND id NOT IN (' . implode( ', ', array_map( 'intval', (array) $outIds ) ) . ') '; } $sql_str = "SELECT " . implode( ', ', (array) $list ) . " FROM {$this->_tableMaster} WHERE $where ORDER BY name"; $quiz_list = $this->_wpdb->get_results( $sql_str, ARRAY_A ); if ( ! empty( $quiz_list ) ) { $quiz_pro_ids = wp_list_pluck( $quiz_list, 'id' ); $sql_str = "SELECT postmeta.meta_value as quiz_pro_id FROM {$this->_wpdb->posts} AS posts INNER JOIN {$this->_wpdb->postmeta} as postmeta ON posts.ID = postmeta.post_id WHERE posts.post_type='". learndash_get_post_type_slug( 'quiz' ) . "' AND posts.post_status = 'publish' AND postmeta.meta_key='quiz_pro_id' AND postmeta.meta_value IN ( ". implode( ',', $quiz_pro_ids ) . " )"; $quiz_pro_ids = $this->_wpdb->get_col( $sql_str ); if ( ! empty( $quiz_pro_ids ) ) { $quiz_pro_ids = array_map( 'intval', $quiz_pro_ids ); $quiz_pro_ids = array_unique( $quiz_pro_ids ); foreach( $quiz_list as $quiz_idx => $quiz_item ) { if ( ! in_array( $quiz_item['id'], $quiz_pro_ids ) ) { unset( $quiz_list[ $quiz_idx ] ); } } } } return ( array ) $quiz_list; } public function fetchCol($ids, $col) { $ids = implode(', ', array_map('intval', (array)$ids)); return $this->_wpdb->get_col("SELECT {$col} FROM {$this->_tableMaster} WHERE id IN({$ids})"); } public function activateStatitic($quizIds, $lockIpTime) { $quizIds = implode(', ', array_map('intval', (array)$quizIds)); return $this->_wpdb->query($this->_wpdb->prepare( "UPDATE {$this->_tableMaster} SET `statistics_on` = 1, `statistics_ip_lock` = %d WHERE `statistics_on` = 0 AND id IN(".$quizIds.")" , $lockIpTime)); } public function deleteAll($quizId) { return $this->_wpdb->query( $this->_wpdb->prepare( "DELETE m, q, l, p, t, f, sr, s FROM {$this->_tableMaster} AS m LEFT JOIN {$this->_tableQuestion} AS q ON(q.quiz_id = m.id) LEFT JOIN {$this->_tableLock} AS l ON(l.quiz_id = m.id) LEFT JOIN {$this->_tablePrerequisite} AS p ON(p.prerequisite_quiz_id = m.id) LEFT JOIN {$this->_tableToplist} AS t ON(t.quiz_id = m.id) LEFT JOIN {$this->_tableForm} AS f ON(f.quiz_id = m.id) LEFT JOIN {$this->_tableStatisticRef} AS sr ON(sr.quiz_id = m.id) LEFT JOIN {$this->_tableStatistic} AS s ON(s.statistic_ref_id = sr.statistic_ref_id) WHERE m.id = %d" , $quizId) ); } } lib/model/WpProQuiz_Model_Mapper.php 0000666 00000002773 15214236625 0013512 0 ustar 00 _wpdb = $wpdb; //$this->_prefix = $wpdb->prefix . 'wp_pro_quiz_'; $this->_prefix = LDLMS_DB::get_table_prefix( 'wpproquiz' ); $this->_tableQuestion = LDLMS_DB::get_table_name( 'quiz_question' ); $this->_tableMaster = LDLMS_DB::get_table_name( 'quiz_master' ); $this->_tableLock = LDLMS_DB::get_table_name( 'quiz_lock' ); $this->_tableStatistic = LDLMS_DB::get_table_name( 'quiz_statistic' ); $this->_tableToplist = LDLMS_DB::get_table_name( 'quiz_toplist' ); $this->_tablePrerequisite = LDLMS_DB::get_table_name( 'quiz_prerequisite' ); $this->_tableCategory = LDLMS_DB::get_table_name( 'quiz_category' ); $this->_tableStatisticRef = LDLMS_DB::get_table_name( 'quiz_statistic_ref' ); $this->_tableForm = LDLMS_DB::get_table_name( 'quiz_form' ); $this->_tableTemplate = LDLMS_DB::get_table_name( 'quiz_template' ); } public function getInsertId() { return $this->_wpdb->insert_id; } } lib/model/WpProQuiz_Model_StatisticRefMapper.php 0000666 00000037317 15214236625 0016041 0 ustar 00 0) $where = ' AND is_old = 0 '; else $where = ' AND statistic_ref_id = '.(int)$testId; $results = $this->_wpdb->get_results( $this->_wpdb->prepare( "SELECT * FROM {$this->_tableStatisticRef} WHERE quiz_id = %d AND user_id = %d {$where} ORDER BY create_time ASC" , $quizId, $userId) , ARRAY_A); foreach ($results as $row) { $row['form_data'] = null; $r[] = new WpProQuiz_Model_StatisticRefModel($row); } return $r; } public function fetchAllByRef($statisticRefId) { if ( ! empty( $statisticRefId ) ) { $where = 'sf.statistic_ref_id = %d'; $results = $this->_wpdb->get_results( $this->_wpdb->prepare( "SELECT sf.* FROM {$this->_tableStatisticRef} AS sf WHERE {$where}" , $statisticRefId) , ARRAY_A); foreach ($results as $row) { $row['form_data'] = $row['form_data'] === null ? null : @json_decode($row['form_data'], true); return new WpProQuiz_Model_StatisticRefModel($row); } } } public function fetchByRefId($refIdUserId, $quizId, $avg = FALSE) { $where = $avg ? 'sf.user_id = %d' : 'sf.statistic_ref_id = %d'; $results = $this->_wpdb->get_results( $this->_wpdb->prepare( "SELECT sf.*, MIN(sf.create_time) AS min_create_time, MAX(sf.create_time) AS max_create_time FROM {$this->_tableStatisticRef} AS sf WHERE {$where} AND sf.quiz_id = %d" , $refIdUserId, $quizId) , ARRAY_A); foreach ($results as $row) { $row['form_data'] = $row['form_data'] === null ? null : @json_decode($row['form_data'], true); return new WpProQuiz_Model_StatisticRefModel($row); } } public function fetchAvg($quizId, $userId) { $r = array(); $results = $this->_wpdb->get_results( $this->_wpdb->prepare(' SELECT question_id, SUM(correct_count) AS correct_count, SUM(incorrect_count) AS incorrect_count, SUM(hint_count) AS hint_count, SUM(points) AS points, (SUM(question_time) / COUNT(DISTINCT sf.statistic_ref_id)) AS question_time FROM '.$this->_tableStatistic.' AS s, '.$this->_tableStatisticRef.' AS sf WHERE s.statistic_ref_id = sf.statistic_ref_id AND sf.quiz_id = %d AND sf.user_id = %d GROUP BY s.question_id ', $quizId, $userId) , ARRAY_A); foreach ($results as $row) { $r[] = new WpProQuiz_Model_Statistic($row); } return $r; } public function fetchOverview($quizId, $onlyCompleded, $start, $limit) { $sql = 'SELECT u.`user_login`, u.`display_name`, u.ID AS user_id, SUM(s.`correct_count`) as correct_count, SUM(s.`incorrect_count`) as incorrect_count, SUM(s.`hint_count`) as hint_count, SUM(s.`points`) as points, (SUM(s.question_time)) as question_time FROM `'.$this->_wpdb->users.'` AS u '.($onlyCompleded ? 'INNER' : 'LEFT').' JOIN `'.$this->_tableStatisticRef.'` AS sf ON (sf.user_id = u.ID AND sf.quiz_id = %d) LEFT JOIN `'.$this->_tableStatistic.'` AS s ON ( s.statistic_ref_id = sf.statistic_ref_id ) GROUP BY u.ID ORDER BY u.`user_login` LIMIT %d , %d'; $a = array(); $results = $this->_wpdb->get_results( $this->_wpdb->prepare($sql, $quizId, $start, $limit), ARRAY_A); foreach($results as $row) { $row['user_name'] = $row['user_login'] . ' ('. $row['display_name'] .')'; $a[] = new WpProQuiz_Model_StatisticOverview($row); } return $a; } public function countOverview($quizId, $onlyCompleded) { if($onlyCompleded) { return $this->_wpdb->get_var( $this->_wpdb->prepare( "SELECT COUNT(user_id) FROM {$this->_tableStatisticRef} WHERE quiz_id = %d", $quizId ) ); } else { return $this->_wpdb->get_var( "SELECT COUNT(ID) FROM {$this->_wpdb->users}" ); } } public function fetchByQuiz($quizId) { $sql = 'SELECT (SUM(`correct_count`) + SUM(`incorrect_count`)) as count, SUM(`points`) as points FROM '.$this->_tableStatisticRef.' AS sf, '.$this->_tableStatistic.' AS s WHERE sf.quiz_id = %d AND s.statistic_ref_id = sf.statistic_ref_id'; return $this->_wpdb->get_row( $this->_wpdb->prepare($sql, $quizId), ARRAY_A); } /** * * @param WpProQuiz_Model_StatisticRefModel $statisticRefModel * @param WpProQuiz_Model_Statistic $statisticModel */ public function statisticSave($statisticRefModel, $statisticModel) { $values = array(); $refId = null; $isOld = false; // if(!$statisticRefModel->getUserId()) { // $isOld = true; // $refId = $this->_wpdb->get_var( // $this->_wpdb->prepare(' // SELECT statistic_ref_id // FROM '.$this->_tableStatisticRef.' // WHERE quiz_id = %d AND user_id = %d // ', $statisticRefModel->getQuizId(), $statisticRefModel->getUserId()) // ); // } if($refId === null) { $refData = array( 'quiz_id' => $statisticRefModel->getQuizId(), 'user_id' => $statisticRefModel->getUserId(), 'create_time' => $statisticRefModel->getCreateTime(), 'is_old' => (int)$isOld ); $refFormat = array('%d', '%d', '%d', '%d'); if($statisticRefModel->getFormData() !== null && is_array($statisticRefModel->getFormData())) { $refData['form_data'] = @json_encode($statisticRefModel->getFormData()); $refFormat[] = '%s'; } $this->_wpdb->insert($this->_tableStatisticRef, $refData, $refFormat); $refId = $this->_wpdb->insert_id; } if ( !empty( $refId ) ) { foreach($statisticModel as $d) { $answerData = $d->getAnswerData() === null ? 'NULL' : $this->_wpdb->prepare('%s', json_encode($d->getAnswerData())); $values[] = '( '.implode(', ', array( 'statistic_ref_id' => $refId, 'question_id' => $d->getQuestionId(), 'correct_count' => $d->getCorrectCount(), 'incorrect_count' => $d->getIncorrectCount(), 'hint_count' => $d->getHintCount(), 'points' => $d->getPoints(), 'question_time' => $d->getQuestionTime(), 'answer_data' => $answerData )).' )'; } $this->_wpdb->query( 'INSERT INTO '.$this->_tableStatistic.' ( statistic_ref_id, question_id, correct_count, incorrect_count, hint_count, points, question_time, answer_data ) VALUES '.implode(', ', $values) ); } return $refId; } public function deleteUser($quizId, $userId) { return $this->_wpdb->query( $this->_wpdb->prepare(' DELETE s, sf FROM '.$this->_tableStatistic.' AS s INNER JOIN '.$this->_tableStatisticRef.' AS sf ON s.statistic_ref_id = sf.statistic_ref_id WHERE sf.quiz_id = %d AND sf.user_id = %d ', $quizId, $userId) ); } public function deleteAll($quizId) { return $this->_wpdb->query( $this->_wpdb->prepare(' DELETE s, sf FROM '.$this->_tableStatistic.' AS s INNER JOIN '.$this->_tableStatisticRef.' AS sf ON s.statistic_ref_id = sf.statistic_ref_id WHERE sf.quiz_id = %d ', $quizId) ); } public function deleteUserTest($quizId, $userId, $testId) { if(!$testId) return $this->deleteUser($quizId, $userId); return $this->_wpdb->query( $this->_wpdb->prepare(' DELETE s, sf FROM '.$this->_tableStatistic.' AS s INNER JOIN '.$this->_tableStatisticRef.' AS sf ON s.statistic_ref_id = sf.statistic_ref_id WHERE sf.quiz_id = %d AND sf.user_id = %d AND sf.statistic_ref_id = %d ', $quizId, $userId, $testId) ); } public function deleteQuestion($questionId) { return $this->_wpdb->delete($this->_tableStatistic, array('question_id' => $questionId), array('%d')); } public function fetchFormOverview($quizId, $page, $limit, $onlyUser = 0) { switch ($onlyUser) { case 1: $where = ' AND sf.user_id > 0 '; break; case 2: $where = ' AND sf.user_id = 0 '; break; default: $where = ''; } $result = $this->_wpdb->get_results( $this->_wpdb->prepare(' SELECT u.`user_login`, u.`display_name`, u.ID AS user_id, sf.*, SUM(s.correct_count) AS correct_count, SUM(s.incorrect_count) AS incorrect_count, SUM(s.points) AS points FROM '.$this->_tableStatisticRef.' AS sf INNER JOIN '.$this->_tableStatistic.' AS s ON(s.statistic_ref_id = sf.statistic_ref_id) LEFT JOIN '.$this->_wpdb->users.' AS u ON(u.ID = sf.user_id) WHERE quiz_id = %d AND sf.form_data IS NOT NULL '.$where.' GROUP BY sf.statistic_ref_id ORDER BY sf.create_time DESC LIMIT %d, %d ', $quizId, $page, $limit), ARRAY_A ); $r = array(); foreach($result as $row) { $row['user_name'] = $row['user_login'] . ' ('. $row['display_name'] .')'; $r[] = new WpProQuiz_Model_StatisticFormOverview($row); } return $r; } public function fetchHistory($quizId, $page, $limit, $users = -1, $startTime = 0, $endTime = 0) { $where = ''; $timeWhere = ''; switch ($users) { case -3: //only anonym $where = 'AND user_id = 0'; break; case -2: //only reg user $where = 'AND user_id > 0'; break; case -1: //all $where = ''; break; default: $where = 'AND user_id = '.(int)$users; break; } if($startTime) $timeWhere = 'AND create_time >= '.(int)$startTime; if($endTime) $timeWhere .= ' AND create_time <= '.(int)$endTime; $result = $this->_wpdb->get_results( $this->_wpdb->prepare(' SELECT u.`user_login`, u.`display_name`, u.ID AS user_id, sf.*, SUM(s.correct_count) AS correct_count, SUM(s.incorrect_count) AS incorrect_count, SUM(s.points) AS points, SUM(q.points) AS g_points FROM '.$this->_tableStatisticRef.' AS sf INNER JOIN '.$this->_tableStatistic.' AS s ON(s.statistic_ref_id = sf.statistic_ref_id) LEFT JOIN '.$this->_wpdb->users.' AS u ON(u.ID = sf.user_id) INNER JOIN '.$this->_tableQuestion.' AS q ON(q.id = s.question_id) WHERE sf.quiz_id = %d AND sf.is_old = 0 '.$where.' '.$timeWhere.' GROUP BY sf.statistic_ref_id ORDER BY sf.create_time DESC LIMIT %d, %d ', $quizId, $page, $limit), ARRAY_A ); $r = array(); foreach($result as $row) { if(!empty($row['user_login'])) $row['user_name'] = $row['user_login'] . ' ('. $row['display_name'] .')'; $r[] = new WpProQuiz_Model_StatisticHistory($row); } return $r; } public function countFormOverview($quizId, $onlyUser) { switch ($onlyUser) { case 1: $where = ' AND user_id > 0 '; break; case 2: $where = ' AND user_id = 0 '; break; default: $where = ''; } return $this->_wpdb->get_var( $this->_wpdb->prepare( "SELECT COUNT(user_id) FROM {$this->_tableStatisticRef} WHERE quiz_id = %d AND form_data IS NOT NULL ".$where, $quizId ) ); } public function countHistory($quizId, $users = -1, $startTime = 0, $endTime = 0) { $timeWhere = ''; $where = ''; switch ($users) { case -3: //only anonym $where = 'AND user_id = 0'; break; case -2: //only reg user $where = 'AND user_id > 0'; break; case -1: //all $where = ''; break; default: $where = 'AND user_id = '.(int)$users; break; } if($startTime) $timeWhere = 'AND create_time >= '.(int)$startTime; if($endTime) $timeWhere .= ' AND create_time <= '.(int)$endTime; return $this->_wpdb->get_var( $this->_wpdb->prepare( "SELECT COUNT(user_id) FROM {$this->_tableStatisticRef} WHERE quiz_id = %d AND is_old = 0 {$where} {$timeWhere}", $quizId ) ); } public function deleteByRefId($refId) { return $this->_wpdb->query( $this->_wpdb->prepare(' DELETE s, sf FROM '.$this->_tableStatistic.' AS s INNER JOIN '.$this->_tableStatisticRef.' AS sf ON (s.statistic_ref_id = sf.statistic_ref_id) WHERE sf.statistic_ref_id = %d ', $refId) ); } public function deleteByUserIdQuizId($userId, $quizId) { return $this->_wpdb->query( $this->_wpdb->prepare(' DELETE s, sf FROM '.$this->_tableStatistic.' AS s INNER JOIN '.$this->_tableStatisticRef.' AS sf ON (s.statistic_ref_id = sf.statistic_ref_id) WHERE sf.user_id = %d AND sf.quiz_id = %d ', $userId, $quizId) ); } public function fetchStatisticOverview($quizId, $onlyCompleded, $start, $limit) { $a = array(); $results = $this->_wpdb->get_results( $this->_wpdb->prepare( '( SELECT u.`user_login`, u.`display_name`, u.ID AS user_id, SUM(s.`correct_count`) as correct_count, SUM(s.`incorrect_count`) as incorrect_count, SUM(s.`hint_count`) as hint_count, SUM(s.`points`) as points, AVG(s.question_time) as question_time, SUM(q.points * (s.correct_count + s.incorrect_count)) AS g_points FROM '.$this->_wpdb->users.' AS u '.($onlyCompleded ? 'INNER' : 'LEFT').' JOIN '.$this->_tableStatisticRef.' AS sf ON (sf.user_id = u.ID AND sf.quiz_id = %d) LEFT JOIN '.$this->_tableStatistic.' AS s ON ( s.statistic_ref_id = sf.statistic_ref_id ) LEFT JOIN '.$this->_tableQuestion.' AS q ON(q.id = s.question_id) GROUP BY u.ID ) UNION ( SELECT NULL, NULL, 0, SUM(s.`correct_count`) as correct_count, SUM(s.`incorrect_count`) as incorrect_count, SUM(s.`hint_count`) as hint_count, SUM(s.`points`) as points, AVG(s.question_time) as question_time, SUM(q.points * (s.correct_count + s.incorrect_count)) AS g_points FROM '.$this->_tableMaster.' AS m '.($onlyCompleded ? 'INNER' : 'LEFT').' JOIN '.$this->_tableStatisticRef.' AS sf ON(sf.quiz_id = m.id AND sf.user_id = 0) LEFT JOIN '.$this->_tableStatistic.' AS s ON (s.statistic_ref_id = sf.statistic_ref_id) LEFT JOIN '.$this->_tableQuestion.' AS q ON (q.id = s.question_id) WHERE m.id = %d GROUP BY sf.user_id ) ORDER BY user_login LIMIT %d, %d', $quizId, $quizId, $start, $limit), ARRAY_A ); foreach($results as $row) { if(!empty($row['user_login'])) $row['user_name'] = $row['user_login'] . ' ('. $row['display_name'] .')'; $a[] = new WpProQuiz_Model_StatisticOverview($row); } return $a; } public function countOverviewNew($quizId, $onlyCompleded) { return $this->_wpdb->get_var( $this->_wpdb->prepare( 'SELECT COUNT(*) as g_count FROM ( (SELECT u.ID FROM '.$this->_wpdb->users.' AS u '.($onlyCompleded ? 'INNER' : 'LEFT').' JOIN '.$this->_tableStatisticRef.' AS sf ON (sf.user_id = u.ID AND sf.quiz_id = %d) LEFT JOIN '.$this->_tableStatistic.' AS s ON ( s.statistic_ref_id = sf.statistic_ref_id ) LEFT JOIN '.$this->_tableQuestion.' AS q ON(q.id = s.question_id) GROUP BY u.ID ) UNION (SELECT sf.user_id FROM '.$this->_tableMaster.' AS m '.($onlyCompleded ? 'INNER' : 'LEFT').' JOIN '.$this->_tableStatisticRef.' AS sf ON(sf.quiz_id = m.id AND sf.user_id = 0) LEFT JOIN '.$this->_tableStatistic.' AS s ON (s.statistic_ref_id = sf.statistic_ref_id) LEFT JOIN '.$this->_tableQuestion.' AS q ON (q.id = s.question_id) WHERE m.id = %d GROUP BY sf.user_id) ) AS c_all', $quizId, $quizId)); } public function fetchFrontAvg($quizId) { return $this->_wpdb->get_row($this->_wpdb->prepare( "SELECT SUM(s.points) AS points, SUM(q.points * (s.correct_count + s.incorrect_count)) AS g_points FROM {$this->_tableStatisticRef} AS sf INNER JOIN {$this->_tableStatistic} AS s ON ( s.statistic_ref_id = sf.statistic_ref_id ) INNER JOIN {$this->_tableQuestion} AS q ON ( q.id = s.question_id ) WHERE sf.quiz_id = %d", $quizId), ARRAY_A); } } lib/model/WpProQuiz_Model_GlobalSettings.php 0000666 00000002070 15214236625 0015175 0 ustar 00 _addRawShortcode = (bool)$_addRawShortcode; return $this; } public function isAddRawShortcode() { return $this->_addRawShortcode; } public function setJsLoadInHead($_jsLoadInHead) { $this->_jsLoadInHead = (bool)$_jsLoadInHead; return $this; } public function isJsLoadInHead() { return $this->_jsLoadInHead; } public function setTouchLibraryDeactivate($_touchLibraryDeactivate) { $this->_touchLibraryDeactivate = (bool)$_touchLibraryDeactivate; return $this; } public function isTouchLibraryDeactivate() { return $this->_touchLibraryDeactivate; } public function setCorsActivated($_corsActivated) { $this->_corsActivated = (bool)$_corsActivated; return $this; } public function isCorsActivated() { return $this->_corsActivated; } } lib/model/WpProQuiz_Model_Category.php 0000666 00000001001 15214236625 0014022 0 ustar 00 _categoryId = (int)$_categoryId; return $this; } public function getCategoryId() { return $this->_categoryId; } public function setCategoryName( $_categoryName = '' ) { $this->_categoryName = (string)$_categoryName; return $this; } public function getCategoryName() { return $this->_categoryName; } } lib/model/WpProQuiz_Model_AnswerTypes.php 0000666 00000006777 15214236625 0014562 0 ustar 00 _answer = (string)$_answer; return $this; } public function getAnswer() { return $this->_answer; } public function setHtml($_html) { $this->_html = (bool)$_html; return $this; } public function isHtml() { return $this->_html; } public function setPoints($_points) { $this->_points = (int)$_points; return $this; } public function getPoints() { return $this->_points; } public function setCorrect($_correct) { $this->_correct = (bool)$_correct; return $this; } public function isCorrect() { return $this->_correct; } public function setSortString($_sortString) { $this->_sortString = (string)$_sortString; return $this; } public function getSortString() { return $this->_sortString; } public function setSortStringHtml($_sortStringHtml) { $this->_sortStringHtml = (bool)$_sortStringHtml; return $this; } public function isSortStringHtml() { return $this->_sortStringHtml; } public function setGraded($_graded) { $this->_graded = (string)$_graded; return $this; } public function isGraded() { return $this->_graded; } public function setGradedType($_gradedType) { $this->_gradedType = (string)$_gradedType; return $this; } public function getGradedType() { return $this->_gradedType; } public function setGradingProgression($_gradingProgression) { if ( ( is_null( $_gradingProgression ) ) || ( empty( $_gradingProgression ) ) ) { $_gradingProgression = 'not-graded-none'; } $this->_gradingProgression = (string)$_gradingProgression; return $this; } public function getGradingProgression() { if ( ( is_null( $this->_gradingProgression ) ) || ( empty( $this->_gradingProgression ) ) ) { $this->_gradingProgression = 'not-graded-none'; } return $this->_gradingProgression; } public function get_object_as_array() { $object_vars = array( '_answer' => $this->getAnswer(), '_html' => $this->isHtml(), '_points' => $this->getPoints(), '_correct' => $this->isCorrect(), '_sortString' => $this->getSortString(), '_sortStringHtml' => $this->isSortStringHtml(), '_graded' => $this->isGraded(), '_gradingProgression' => $this->getGradingProgression(), '_gradedType' => $this->getGradedType() ); return $object_vars; } public function set_array_to_object( $array_vars = array() ) { foreach( $array_vars as $key => $value ) { switch( $key ) { case '_answer': $this->setAnswer( $value ); break; case '_html': $this->setHtml( $value ); break; case '_points': $this->setPoints( $value ); break; case '_correct': $this->setCorrect( $value ); break; case '_sortString': $this->setSortString( $value ); break; case '_sortStringHtml': $this->setSortStringHtml( $value ); break; case '_graded': $this->setGraded( $value ); break; case '_gradingProgression': $this->setGradingProgression( $value ); break; case '_gradedType': $this->setGradedType( $value ); break; default: break; } } } } lib/model/WpProQuiz_Model_Toplist.php 0000666 00000003136 15214236625 0013716 0 ustar 00 _toplistId = (int)$_toplistId; return $this; } public function getToplistId() { return $this->_toplistId; } public function setQuizId($_quizId) { $this->_quizId = (int)$_quizId; return $this; } public function getQuizId() { return $this->_quizId; } public function setUserId($_userId) { $this->_userId = (int)$_userId; return $this; } public function getUserId() { return $this->_userId; } public function setDate($_date) { $this->_date = (int)$_date; return $this; } public function getDate() { return $this->_date; } public function setName($_name) { $this->_name = (string)$_name; return $this; } public function getName() { return $this->_name; } public function setEmail($_email) { $this->_email = (string)$_email; return $this; } public function getEmail() { return $this->_email; } public function setPoints($_points) { $this->_points = (int)$_points; return $this; } public function getPoints() { return $this->_points; } public function setResult($_result) { $this->_result = (float)$_result; return $this; } public function getResult() { return $this->_result; } public function setIp($_ip) { $this->_ip = (string)$_ip; return $this; } public function getIp() { return $this->_ip; } } lib/model/WpProQuiz_Model_StatisticRefModel.php 0000666 00000005603 15214236625 0015646 0 ustar 00 _statisticRefId = (int)$_statisticRefId; return $this; } public function getStatisticRefId() { return $this->_statisticRefId; } public function setQuizId($_quizId) { $this->_quizId = (int)$_quizId; return $this; } public function getQuizId() { return $this->_quizId; } public function setUserId($_userId) { $this->_userId = (int)$_userId; return $this; } public function getUserId() { return $this->_userId; } public function setCreateTime($_createTime) { $this->_createTime = (int)$_createTime; return $this; } public function getCreateTime() { return $this->_createTime; } public function setIsOld($_isOld) { $this->_isOld = (bool)$_isOld; return $this; } public function isIsOld() { return $this->_isOld; } public function setFormData($_formData) { $this->_formData = $_formData === null ? null : (array)$_formData; return $this; } public function getFormData() { return $this->_formData; } public function setMinCreateTime($_minCreateTime) { $this->_minCreateTime = (int)$_minCreateTime; return $this; } public function getMinCreateTime() { return $this->_minCreateTime; } public function setMaxCreateTime($_maxCreateTime) { $this->_maxCreateTime = (int)$_maxCreateTime; return $this; } public function getMaxCreateTime() { return $this->_maxCreateTime; } public function get_object_as_array() { $object_vars = array( '_statisticRefId' => $this->getStatisticRefId(), '_quizId' => $this->getQuizId(), '_userId' => $this->getUserId(), '_createTime' => $this->getCreateTime(), '_isOld' => $this->isIsOld(), '_formData' => $this->getFormData(), '_minCreateTime' => $this->getMinCreateTime(), '_maxCreateTime' => $this->getMaxCreateTime() ); return $object_vars; } public function set_array_to_object( $array_vars = array() ) { foreach( $array_vars as $key => $value ) { switch( $key ) { case '_statisticRefId': $this->setStatisticRefId( $value ); break; case '_quizId': $this->setQuizId( $value ); break; case '_userId': $this->setUserId( $value ); break; case '_createTime': $this->setCreateTime( $value ); break; case '_isOld': $this->isIsOld( $value ); break; case '_formData': $this->setFormData( $value ); break; case '_minCreateTime': $this->setMinCreateTime( $value ); break; case '_maxCreateTime': $this->setMaxCreateTime( $value ); break; } } } } lib/model/WpProQuiz_Model_StatisticUser.php 0000666 00000005761 15214236625 0015074 0 ustar 00 _correctCount = (int)$_correctCount; return $this; } public function getCorrectCount() { return $this->_correctCount; } public function setIncorrectCount($_incorrectCount) { $this->_incorrectCount = (int)$_incorrectCount; return $this; } public function getIncorrectCount() { return $this->_incorrectCount; } public function setHintCount($_hintCount) { $this->_hintCount = (int)$_hintCount; return $this; } public function getHintCount() { return $this->_hintCount; } public function setPoints($_points) { $this->_points = (int)$_points; return $this; } public function getPoints() { return $this->_points; } public function setQuestionTime($_questionTime) { $this->_questionTime = (int)$_questionTime; return $this; } public function getQuestionTime() { return $this->_questionTime; } public function setQuestionId($_questionId) { $this->_questionId = (int)$_questionId; return $this; } public function getQuestionId() { return $this->_questionId; } public function setQuestionName($_questionName) { $this->_questionName = (string)$_questionName; return $this; } public function getQuestionName() { return $this->_questionName; } public function setGPoints($_gPoints) { $this->_gPoints = (int)$_gPoints; return $this; } public function getGPoints() { return $this->_gPoints; } public function setCategoryId($_categoryId) { $this->_categoryId = (int)$_categoryId; return $this; } public function getCategoryId() { return $this->_categoryId; } public function setCategoryName($_categoryName) { $this->_categoryName = (string)$_categoryName; return $this; } public function getCategoryName() { return $this->_categoryName; } public function setStatisticAnswerData($_statisticAnswerData) { $this->_statisticAnswerData = $_statisticAnswerData; return $this; } public function getStatisticAnswerData() { return $this->_statisticAnswerData; } public function setQuestionAnswerData($_questionAnswerData) { $this->_questionAnswerData = null; if(WpProQuiz_Helper_Until::saveUnserialize($_questionAnswerData, $into) !== false) { $this->_questionAnswerData = $into; } return $this; } public function getQuestionAnswerData() { return $this->_questionAnswerData; } public function setAnswerType($_answerType) { $this->_answerType = (string)$_answerType; return $this; } public function getAnswerType() { return $this->_answerType; } } lib/model/WpProQuiz_Model_Lock.php 0000666 00000001762 15214236625 0013153 0 ustar 00 _quizId = $_quizId; return $this; } public function getQuizId() { return $this->_quizId; } public function setLockIp($_lockIp) { $this->_lockIp = $_lockIp; return $this; } public function getLockIp() { return $this->_lockIp; } public function setLockDate($_lockDate) { $this->_lockDate = $_lockDate; return $this; } public function getLockDate() { return $this->_lockDate; } public function setUserId($_userId) { $this->_userId = (int)$_userId; return $this; } public function getUserId() { return $this->_userId; } public function setLockType($_lockType) { $this->_lockType = (int)$_lockType; return $this; } public function getLockType() { return $this->_lockType; } } lib/model/WpProQuiz_Model_Template.php 0000666 00000001522 15214236625 0014030 0 ustar 00 _templateId = (int)$_templateId; return $this; } public function getTemplateId() { return $this->_templateId; } public function setName($_name) { $this->_name = (string)$_name; return $this; } public function getName() { return $this->_name; } public function setType($_type) { $this->_type = (int)$_type; return $this; } public function getType() { return $this->_type; } public function setData($_data) { $this->_data = $_data; return $this; } public function getData() { return $this->_data; } } lib/model/WpProQuiz_Model_StatisticOverview.php 0000666 00000003520 15214236625 0015753 0 ustar 00 _correctCount = (int)$_correctCount; return $this; } public function getCorrectCount() { return $this->_correctCount; } public function setIncorrectCount($_incorrectCount) { $this->_incorrectCount = (int)$_incorrectCount; return $this; } public function getIncorrectCount() { return $this->_incorrectCount; } public function setHintCount($_hintCount) { $this->_hintCount = (int)$_hintCount; return $this; } public function getHintCount() { return $this->_hintCount; } public function setPoints($_points) { $this->_points = (int)$_points; return $this; } public function getPoints() { return $this->_points; } public function setUserName($_userName) { $this->_userName = (string)$_userName; return $this; } public function getUserName() { return $this->_userName; } public function setQuizId($_quizId) { $this->_quizId = (int)$_quizId; return $this; } public function getQuizId() { return $this->_quizId; } public function setUserId($_userId) { $this->_userId = (int)$_userId; return $this; } public function getUserId() { return $this->_userId; } public function setQuestionTime($_questionTime) { $this->_questionTime = (int)$_questionTime; return $this; } public function getQuestionTime() { return $this->_questionTime; } public function setGPoints($_gPoints) { $this->_gPoints = (int)$_gPoints; return $this; } public function getGPoints() { return $this->_gPoints; } } lib/model/WpProQuiz_Model_Quiz.php 0000666 00000065705 15214236625 0013222 0 ustar 00 _id = (int) $_id; if ( empty( $this->_quiz_post_id ) ) { $this->_quiz_post_id = learndash_get_quiz_id_by_pro_quiz_id( $this->_id ); } return $this; } public function getId() { return $this->_id; } public function setPostId( $post_id ) { $this->_quiz_post_id = (int)$post_id; return $this; } public function getPostId() { return $this->_quiz_post_id; } public function setName($_name) { $this->_name = (string)$_name; return $this; } public function getName() { return $this->_name; } public function setText($_text) { $this->_text = (string)$_text; return $this; } public function getText() { return $this->_text; } public function setResultText($_resultText = '') { if (is_null( $_resultText )) $_resultText = ''; $this->_resultText = $_resultText; return $this; } public function getResultText() { if ( is_null( $this->_resultText ) ) { $this->_resultText = array(); } else if ( is_string( $this->_resultText ) ) { $this->_resultText = array( 'prozent' => array(0), 'activ' => array(1), 'text' => array( $this->_resultText ), ); } $this->_resultText = learndash_quiz_result_message_sort( $this->_resultText ); return $this->_resultText; } public function setTitleHidden($_titleHidden) { $this->_titleHidden = (bool)$_titleHidden; return $this; } public function isTitleHidden() { return $this->_titleHidden; } public function setQuestionRandom($_questionRandom) { $this->_questionRandom = (bool)$_questionRandom; return $this; } public function isQuestionRandom() { return $this->_questionRandom; } public function setAnswerRandom($_answerRandom) { $this->_answerRandom = (bool)$_answerRandom; return $this; } public function isAnswerRandom() { return $this->_answerRandom; } public function setTimeLimit($_timeLimit) { $this->_timeLimit = (int)$_timeLimit; return $this; } public function getTimeLimit() { return $this->_timeLimit; } public function setTimeLimitCookie($_timeLimitCookie) { $this->_timeLimitCookie = (int)$_timeLimitCookie; return $this; } // The TimeLimitCookie var does NOT follow the convention for the WPProQuiz in that it is not stored into the wp_wp_pro_quiz_master table // Instead it is read from and save to the post meta table public function getTimeLimitCookie() { if ( ( property_exists( $this, '_quiz_post_id') ) && ( !empty( $this->_quiz_post_id ) ) ) { $this->_timeLimitCookie = get_post_meta($this->_quiz_post_id, '_timeLimitCookie', true); } return absint( $this->_timeLimitCookie ); } public function saveTimeLimitCookie() { if ( ( property_exists( $this, '_quiz_post_id') ) && ( !empty( $this->_quiz_post_id ) ) ) { return update_post_meta( $this->_quiz_post_id, '_timeLimitCookie', $this->_timeLimitCookie ); } } public function getViewProfileStatistics() { if ( ( property_exists( $this, '_quiz_post_id') ) && ( !empty( $this->_quiz_post_id ) ) ) { $this->_viewPofileStatistics = get_post_meta($this->_quiz_post_id, '_viewProfileStatistics', true); } // standardize the value if ( '1' === $this->_viewPofileStatistics ) { $this->_viewPofileStatistics = true; } else { $this->_viewPofileStatistics = false; } return apply_filters( 'learndash_quiz_default_viewPofileStatistics', $this->_viewPofileStatistics ); } public function setViewProfileStatistics( $_viewPofileStatistics ) { $this->_viewPofileStatistics = $_viewPofileStatistics; } public function saveViewProfileStatistics() { if ( property_exists( $this, '_quiz_post_id') ) { return update_post_meta( $this->_quiz_post_id, '_viewProfileStatistics', $this->_viewPofileStatistics ); } } public function setStatisticsOn($_statisticsOn) { $this->_statisticsOn = (bool)$_statisticsOn; return $this; } public function isStatisticsOn() { return $this->_statisticsOn; } public function setStatisticsIpLock($_statisticsIpLock) { $this->_statisticsIpLock = (int)$_statisticsIpLock; return $this; } public function getStatisticsIpLock() { return $this->_statisticsIpLock; } public function setResultGradeEnabled($_resultGradeEnabled) { //$this->_resultGradeEnabled = (bool)$_resultGradeEnabled; $this->_resultGradeEnabled = true; return $this; } public function isResultGradeEnabled() { //return $this->_resultGradeEnabled; return true; } public function setShowPoints($_showPoints) { $this->_showPoints = (bool)$_showPoints; return $this; } public function isShowPoints() { return $this->_showPoints; } public function fetchSumQuestionPoints() { $m = new WpProQuiz_Model_QuizMapper(); return $m->sumQuestionPoints($this->_id); } public function fetchCountQuestions() { $m = new WpProQuiz_Model_QuizMapper(); return $m->countQuestion($this->_id); } public function setBtnRestartQuizHidden($_btnRestartQuizHidden) { $this->_btnRestartQuizHidden = (bool)$_btnRestartQuizHidden; return $this; } public function isBtnRestartQuizHidden() { return $this->_btnRestartQuizHidden; } public function setBtnViewQuestionHidden($_btnViewQuestionHidden) { $this->_btnViewQuestionHidden = (bool)$_btnViewQuestionHidden; return $this; } public function isBtnViewQuestionHidden() { return $this->_btnViewQuestionHidden; } public function setQuizRunOnce($_quizRunOnce) { $this->_quizRunOnce = (bool)$_quizRunOnce; return $this; } public function isQuizRunOnce() { return $this->_quizRunOnce; } public function setQuizRunOnceCookie($_quizRunOnceCookie) { $this->_quizRunOnceCookie = (bool)$_quizRunOnceCookie; return $this; } public function isQuizRunOnceCookie() { return $this->_quizRunOnceCookie; } public function setQuizRunOnceType($_quizRunOnceType) { $this->_quizRunOnceType = (int)$_quizRunOnceType; return $this; } public function getQuizRunOnceType() { return $this->_quizRunOnceType; } public function setQuizRunOnceTime($_quizRunOnceTime) { $this->_quizRunOnceTime = (int)$_quizRunOnceTime; return $this; } public function getQuizRunOnceTime() { return $this->_quizRunOnceTime; } public function setNumberedAnswer($_numberedAnswer) { $this->_numberedAnswer = (bool)$_numberedAnswer; return $this; } public function isNumberedAnswer() { return $this->_numberedAnswer; } public function setHideAnswerMessageBox($_hideAnswerMessageBox) { $this->_hideAnswerMessageBox = (bool)$_hideAnswerMessageBox; return $this; } public function isHideAnswerMessageBox() { return $this->_hideAnswerMessageBox; } public function setDisabledAnswerMark($_disabledAnswerMark) { $this->_disabledAnswerMark = (bool)$_disabledAnswerMark; return $this; } public function isDisabledAnswerMark() { return $this->_disabledAnswerMark; } public function setShowMaxQuestion($_showMaxQuestion) { $this->_showMaxQuestion = (bool)$_showMaxQuestion; return $this; } public function isShowMaxQuestion() { return $this->_showMaxQuestion; } public function setShowMaxQuestionValue($_showMaxQuestionValue) { $this->_showMaxQuestionValue = (int)$_showMaxQuestionValue; return $this; } public function getShowMaxQuestionValue() { return $this->_showMaxQuestionValue; } public function setShowMaxQuestionPercent($_showMaxQuestionPercent) { $this->_showMaxQuestionPercent = (bool)$_showMaxQuestionPercent; return $this; } public function isShowMaxQuestionPercent() { return $this->_showMaxQuestionPercent; } public function setToplistActivated($_toplistActivated) { $this->_toplistActivated = (bool)$_toplistActivated; return $this; } public function isToplistActivated() { return $this->_toplistActivated; } public function setToplistDataAddPermissions($_toplistDataAddPermissions) { $this->_toplistDataAddPermissions = (int)$_toplistDataAddPermissions; return $this; } public function getToplistDataAddPermissions() { return $this->_toplistDataAddPermissions; } public function setToplistDataSort($_toplistDataSort) { $this->_toplistDataSort = (int)$_toplistDataSort; return $this; } public function getToplistDataSort() { return $this->_toplistDataSort; } public function setToplistDataAddMultiple($_toplistDataAddMultiple) { $this->_toplistDataAddMultiple = (bool)$_toplistDataAddMultiple; return $this; } public function isToplistDataAddMultiple() { return $this->_toplistDataAddMultiple; } public function setToplistDataAddBlock($_toplistDataAddBlock) { $this->_toplistDataAddBlock = (int)$_toplistDataAddBlock; return $this; } public function getToplistDataAddBlock() { return $this->_toplistDataAddBlock; } public function setToplistDataShowLimit($_toplistDataShowLimit) { $this->_toplistDataShowLimit = (int)$_toplistDataShowLimit; return $this; } public function getToplistDataShowLimit() { return $this->_toplistDataShowLimit; } public function setToplistData($_toplistData) { if(!empty($_toplistData)) { $d = unserialize($_toplistData); if($d !== false) { $this->setModelData($d); } } return $this; } public function getToplistData() { $a = array( 'toplistDataAddPermissions' => $this->getToplistDataAddPermissions(), 'toplistDataSort' => $this->getToplistDataSort(), 'toplistDataAddMultiple' => $this->isToplistDataAddMultiple(), 'toplistDataAddBlock' => $this->getToplistDataAddBlock(), 'toplistDataShowLimit' => $this->getToplistDataShowLimit(), 'toplistDataShowIn' => $this->getToplistDataShowIn(), 'toplistDataCaptcha' => $this->isToplistDataCaptcha(), 'toplistDataAddAutomatic' => $this->isToplistDataAddAutomatic() ); return serialize($a); } public function setToplistDataShowIn($_toplistDataShowIn) { $this->_toplistDataShowIn = (int)$_toplistDataShowIn; return $this; } public function getToplistDataShowIn() { return $this->_toplistDataShowIn; } public function setToplistDataCaptcha($_toplistDataCaptcha) { $this->_toplistDataCaptcha = (bool)$_toplistDataCaptcha; return $this; } public function isToplistDataCaptcha() { return $this->_toplistDataCaptcha; } public function setShowAverageResult($_showAverageResult) { $this->_showAverageResult = (bool)$_showAverageResult; return $this; } public function isShowAverageResult() { return $this->_showAverageResult; } public function setPrerequisite($_prerequisite) { $this->_prerequisite = (bool)$_prerequisite; return $this; } public function isPrerequisite() { return $this->_prerequisite; } public function setToplistDataAddAutomatic($_toplistDataAddAutomatic) { $this->_toplistDataAddAutomatic = (bool)$_toplistDataAddAutomatic; return $this; } public function isToplistDataAddAutomatic() { return $this->_toplistDataAddAutomatic; } public function setQuizModus($_quizModus) { $this->_quizModus = (int)$_quizModus; return $this; } public function getQuizModus() { return $this->_quizModus; } public function setShowReviewQuestion($_showReviewQuestion) { $this->_showReviewQuestion = (bool)$_showReviewQuestion; return $this; } public function isShowReviewQuestion() { return $this->_showReviewQuestion; } public function setQuizSummaryHide($_quizSummaryHide) { $this->_quizSummaryHide = (bool)$_quizSummaryHide; return $this; } public function isQuizSummaryHide() { return $this->_quizSummaryHide; } public function setSkipQuestionDisabled($_skipQuestion) { $this->_skipQuestionDisabled = (bool)$_skipQuestion; return $this; } public function isSkipQuestionDisabled() { return $this->_skipQuestionDisabled; } public function setEmailNotification($_emailNotification) { $this->_emailNotification = (int)$_emailNotification; return $this; } public function getEmailNotification() { return $this->_emailNotification; } public function setUserEmailNotification($_userEmailNotification) { $this->_userEmailNotification = (bool)$_userEmailNotification; return $this; } public function isUserEmailNotification() { return $this->_userEmailNotification; } public function setShowCategoryScore($_showCategoryScore) { $this->_showCategoryScore = (bool)$_showCategoryScore; return $this; } public function isShowCategoryScore() { return $this->_showCategoryScore; } public function setHideResultCorrectQuestion($_hideResultCorrectQuestion) { $this->_hideResultCorrectQuestion = (bool)$_hideResultCorrectQuestion; return $this; } public function isHideResultCorrectQuestion() { return $this->_hideResultCorrectQuestion; } public function setHideResultQuizTime($_hideResultQuizTime) { $this->_hideResultQuizTime = (bool)$_hideResultQuizTime; return $this; } public function isHideResultQuizTime() { return $this->_hideResultQuizTime; } public function setHideResultPoints($_hideResultPoints) { $this->_hideResultPoints = (bool)$_hideResultPoints; return $this; } public function isHideResultPoints() { return $this->_hideResultPoints; } public function setAutostart($_autostart) { $this->_autostart = (bool)$_autostart; return $this; } public function isAutostart() { return $this->_autostart; } public function setForcingQuestionSolve($_forcingQuestionSolve) { $this->_forcingQuestionSolve = (bool)$_forcingQuestionSolve; return $this; } public function isForcingQuestionSolve() { return $this->_forcingQuestionSolve; } public function setHideQuestionPositionOverview($_hideQuestionPositionOverview) { $this->_hideQuestionPositionOverview = (bool)$_hideQuestionPositionOverview; return $this; } public function isHideQuestionPositionOverview() { return $this->_hideQuestionPositionOverview; } public function setHideQuestionNumbering($_hideQuestionNumbering) { $this->_hideQuestionNumbering = (bool)$_hideQuestionNumbering; return $this; } public function isHideQuestionNumbering() { return $this->_hideQuestionNumbering; } public function setFormActivated($_formActivated) { $this->_formActivated = (bool)$_formActivated; return $this; } public function isFormActivated() { return $this->_formActivated; } public function setFormShowPosition($_formShowPosition) { $this->_formShowPosition = (int)$_formShowPosition; return $this; } public function getFormShowPosition() { return $this->_formShowPosition; } public function setStartOnlyRegisteredUser($_startOnlyRegisteredUser) { $this->_startOnlyRegisteredUser = (bool)$_startOnlyRegisteredUser; return $this; } public function isStartOnlyRegisteredUser() { return $this->_startOnlyRegisteredUser; } public function setQuestionsPerPage($_questionsPerPage) { $this->_questionsPerPage = (int)$_questionsPerPage; return $this; } public function getQuestionsPerPage() { return $this->_questionsPerPage; } public function setSortCategories($_sortCategories) { $this->_sortCategories = (bool)$_sortCategories; return $this; } public function isSortCategories() { return $this->_sortCategories; } public function setShowCategory($_showCategory) { $this->_showCategory = (bool)$_showCategory; return $this; } public function isShowCategory() { return $this->_showCategory; } public function get_object_as_array() { $object_vars = array( '_quiz_post_id' => 0, '_name' => $this->getName(), //'_text' => $this->getText(), '_resultText' => $this->getResultText(), '_titleHidden' => $this->isTitleHidden(), '_btnRestartQuizHidden' => $this->isBtnRestartQuizHidden(), '_btnViewQuestionHidden' => $this->isBtnViewQuestionHidden(), '_questionRandom' => $this->isQuestionRandom(), '_answerRandom' => $this->isAnswerRandom(), '_timeLimit' => $this->getTimeLimit(), '_timeLimitCookie' => $this->getTimeLimitCookie(), '_statisticsOn' => $this->isStatisticsOn(), '_viewPofileStatistics' => $this->getViewProfileStatistics(), '_statisticsIpLock' => $this->getStatisticsIpLock(), '_resultGradeEnabled' => $this->isResultGradeEnabled(), '_showPoints' => $this->isShowPoints(), '_quizRunOnce' => $this->isQuizRunOnce(), '_quizRunOnceType' => $this->getQuizRunOnceType(), '_quizRunOnceCookie' => $this->isQuizRunOnceCookie(), '_quizRunOnceTime' => $this->getQuizRunOnceTime(), '_numberedAnswer' => $this->isNumberedAnswer(), '_hideAnswerMessageBox' => $this->isHideAnswerMessageBox(), '_disabledAnswerMark' => $this->isDisabledAnswerMark(), '_showMaxQuestion' => $this->isShowMaxQuestion(), '_showMaxQuestionValue' => $this->getShowMaxQuestionValue(), '_showMaxQuestionPercent' => $this->isShowMaxQuestionPercent(), '_toplistActivated' => $this->isToplistActivated(), '_toplistDataAddPermissions' => $this->getToplistDataAddPermissions(), '_toplistDataSort' => $this->getToplistDataSort(), '_toplistDataAddMultiple' => $this->isToplistDataAddMultiple(), '_toplistDataAddBlock' => $this->getToplistDataAddBlock(), '_toplistDataShowLimit' => $this->getToplistDataShowLimit(), '_toplistDataShowIn' => $this->getToplistDataShowIn(), '_toplistDataCaptcha' => $this->isToplistDataCaptcha(), '_toplistData' => $this->getToplistData(), '_showAverageResult' => $this->isShowAverageResult(), '_prerequisite' => $this->isPrerequisite(), '_toplistDataAddAutomatic' => $this->isToplistDataAddAutomatic(), '_quizModus' => $this->getQuizModus(), '_showReviewQuestion' => $this->isShowReviewQuestion(), '_quizSummaryHide' => $this->isQuizSummaryHide(), '_skipQuestionDisabled' => $this->isSkipQuestionDisabled(), '_emailNotification' => $this->getEmailNotification(), '_userEmailNotification' => $this->isUserEmailNotification(), '_showCategoryScore' => $this->isShowCategoryScore(), '_hideResultCorrectQuestion' => $this->isHideResultCorrectQuestion(), '_hideResultQuizTime' => $this->isHideResultQuizTime(), '_hideResultPoints' => $this->isHideResultPoints(), '_autostart' => $this->isAutostart(), '_forcingQuestionSolve' => $this->isForcingQuestionSolve(), '_hideQuestionPositionOverview' => $this->isHideQuestionPositionOverview(), '_hideQuestionNumbering' => $this->isHideQuestionNumbering(), '_formActivated' => $this->isFormActivated(), '_formShowPosition' => $this->getFormShowPosition(), '_startOnlyRegisteredUser' => $this->isStartOnlyRegisteredUser(), '_questionsPerPage' => $this->getQuestionsPerPage(), '_sortCategories' => $this->isSortCategories(), '_showCategory' => $this->isShowCategory() ); return $object_vars; } public function set_array_to_object( $array_vars = array() ) { $array_vars['_text'] = "AAZZAAZZ"; foreach( $array_vars as $key => $value ) { switch( $key ) { case '_name': $this->setName( $value ); break; case '_text': $this->setText( "AAZZAAZZ" ); break; case '_resultText': $this->setResultText( $value ); break; case '_titleHidden': $this->setTitleHidden( $value ); break; case '_btnRestartQuizHidden': $this->setBtnRestartQuizHidden( $value ); break; case '_btnViewQuestionHidden': $this->setBtnViewQuestionHidden( $value ); break; case '_questionRandom': $this->setQuestionRandom( $value ); break; case '_answerRandom': $this->setAnswerRandom( $value ); break; case '_timeLimit': $this->setTimeLimit( $value ); break; case '_timeLimitCookie': $this->setTimeLimitCookie( $value ); break; case '_statisticsOn': $this->setStatisticsOn( $value ); break; case '_viewPofileStatistics': $this->setViewProfileStatistics( $value ); break; case '_statisticsIpLock': $this->setStatisticsIpLock( $value ); break; case '_resultGradeEnabled': $this->setResultGradeEnabled( $value ); break; case '_showPoints': $this->setShowPoints( $value ); break; case '_quizRunOnce': $this->setQuizRunOnce( $value ); break; case 'setQuizRunOnceCookie': $this->setQuizRunOnceType( $value ); break; case '_quizRunOnceCookie': $this->setQuizRunOnceCookie( $value ); break; case '_quizRunOnceTime': $this->setQuizRunOnceTime( $value ); break; case '_numberedAnswer': $this->setNumberedAnswer( $value ); break; case '_hideAnswerMessageBox': $this->setHideAnswerMessageBox( $value ); break; case '_disabledAnswerMark': $this->setDisabledAnswerMark( $value ); break; case '_showMaxQuestion': $this->setShowMaxQuestion( $value ); break; case '_showMaxQuestionValue': $this->setShowMaxQuestionValue( $value ); break; case '_showMaxQuestionPercent': $this->setShowMaxQuestionPercent( $value ); break; case '_toplistActivated': $this->setToplistActivated( $value ); break; case '_toplistDataAddPermissions': $this->setToplistDataAddPermissions( $value ); break; case '_toplistDataSort': $this->setToplistDataSort( $value ); break; case '_toplistDataAddMultiple': $this->setToplistDataAddMultiple( $value ); break; case '_toplistDataAddBlock': $this->setToplistDataAddBlock( $value ); break; case '_toplistDataShowLimit': $this->setToplistDataShowLimit( $value ); break; case '_toplistDataShowIn': $this->setToplistDataShowIn( $value ); break; case '_toplistDataCaptcha': $this->setToplistDataCaptcha( $value ); break; case '_toplistData': $this->setToplistData( $value ); break; case '_showAverageResult': $this->setShowAverageResult( $value ); break; case '_prerequisite': $this->setPrerequisite( $value ); break; case '_toplistDataAddAutomatic': $this->setToplistDataAddAutomatic( $value ); break; case '_quizModus': $this->setQuizModus( $value ); break; case '_showReviewQuestion': $this->setShowReviewQuestion( $value ); break; case '_quizSummaryHide': $this->setQuizSummaryHide( $value ); break; case '_skipQuestionDisabled': $this->setSkipQuestionDisabled( $value ); break; case '_emailNotification': $this->setEmailNotification( $value ); break; case '_userEmailNotification': $this->setUserEmailNotification( $value ); break; case '_showCategoryScore': $this->setShowCategoryScore( $value ); break; case '_hideResultCorrectQuestion': $this->setHideResultCorrectQuestion( $value ); break; case '_hideResultQuizTime': $this->setHideResultQuizTime( $value ); break; case '_hideResultPoints': $this->setHideResultPoints( $value ); break; case '_autostart': $this->setAutostart( $value ); break; case '_forcingQuestionSolve': $this->setForcingQuestionSolve( $value ); break; case '_hideQuestionPositionOverview': $this->setHideQuestionPositionOverview( $value ); break; case '_hideQuestionNumbering': $this->setHideQuestionNumbering( $value ); break; case '_formActivated': $this->setFormActivated( $value ); break; case '_formShowPosition': $this->setFormShowPosition( $value ); break; case '_startOnlyRegisteredUser': $this->setStartOnlyRegisteredUser( $value ); break; case '_questionsPerPage': $this->setQuestionsPerPage( $value ); break; case '_sortCategories': $this->setSortCategories( $value ); break; case '_showCategory': $this->setShowCategoryScore( $value ); break; default: break; } } } } lib/model/WpProQuiz_Model_LockMapper.php 0000666 00000004051 15214236625 0014312 0 ustar 00 _table = $this->_prefix.'lock'; $this->_table = $this->_tableLock; } public function insert(WpProQuiz_Model_Lock $lock) { $this->_wpdb->insert($this->_table, array( 'quiz_id' => $lock->getQuizId(), 'lock_ip' => $lock->getLockIp(), 'user_id' => $lock->getUserId(), 'lock_type' => $lock->getLockType(), 'lock_date' => $lock->getLockDate(), 'lock_type' => $lock->getLockType() ), array('%d', '%s', '%d', '%d', '%d', '%d')); } public function fetch($quizId, $lockIp, $userId) { $row = $this->_wpdb->get_row( $this->_wpdb->prepare( "SELECT * FROM ". $this->_table. " WHERE quiz_id = %d AND lock_ip = %s AND user_id = %d", $quizId, $lockIp, $userId) ); if($row === null) return null; return new WpProQuiz_Model_Lock($row); } public function isLock($quizId, $lockIp, $userId, $type) { $c = $this->_wpdb->get_var( $this->_wpdb->prepare( "SELECT COUNT(*) FROM {$this->_table} WHERE quiz_id = %d AND lock_ip = %s AND user_id = %d AND lock_type = %d", $quizId, $lockIp, $userId, $type)); if($c === null || $c == 0) return false; return true; } public function deleteOldLock($lockTime, $quizId, $time, $type, $userId = false) { $user = ''; if($userId !== false) { $user = 'AND user_id = '.((int) $userId); } return $this->_wpdb->query( $this->_wpdb->prepare( "DELETE FROM {$this->_table} WHERE quiz_id = %d AND (lock_date + %d) < %d AND lock_type = %d ".$user, $quizId, $lockTime, $time, $type ) ); } public function deleteByQuizId($quizId, $type = false) { $where = array('quiz_id' => $quizId); $whereP = array('%d'); if($type !== false) { $where = array('quiz_id' => $quizId, 'lock_type' => $type); $whereP = array('%d', '%d'); } return $this->_wpdb->delete($this->_tableLock, $where, $whereP); } } lib/model/WpProQuiz_Model_ToplistMapper.php 0000666 00000005511 15214236625 0015062 0 ustar 00 = '.(time() - $clearTime); } $flooding = time() - 15; return $this->_wpdb->get_var( $this->_wpdb->prepare( "SELECT COUNT(*) FROM {$this->_tableToplist} WHERE quiz_id = %d AND (name = %s OR email = %s OR (ip = %s AND date >= {$flooding})) ".$c, $quizId, $name, $email, $ip ) ); } public function countUser($quizId, $userId, $clearTime = null) { $c = ''; if($clearTime !== null) { $c = 'AND date >= '.(time() - $clearTime); } return $this->_wpdb->get_var( $this->_wpdb->prepare( "SELECT COUNT(*) FROM {$this->_tableToplist} WHERE quiz_id = %d AND user_id = %d ".$c, $quizId, $userId ) ); } public function count($quizId) { return $this->_wpdb->get_var( $this->_wpdb->prepare( "SELECT COUNT(*) FROM {$this->_tableToplist} WHERE quiz_id = %d", $quizId ) ); } public function save(WpProQuiz_Model_Toplist $toplist) { $result = $this->_wpdb->insert($this->_tableToplist, array( 'quiz_id' => $toplist->getQuizId(), 'user_id' => $toplist->getUserId(), 'date' => $toplist->getDate(), 'name' => $toplist->getName(), 'email' => $toplist->getEmail(), 'points' => $toplist->getPoints(), 'result' => $toplist->getResult(), 'ip' => $toplist->getIp()), array('%d', '%d', '%d', '%s', '%s', '%d', '%f', '%s')); $toplist->setToplistId($this->_wpdb->insert_id); } public function fetch($quizId, $limit, $sort, $start = 0) { $s = ''; $r = array(); $start = (int)$start; switch ($sort) { case WpProQuiz_Model_Quiz::QUIZ_TOPLIST_SORT_BEST: $s = 'ORDER BY result DESC'; break; case WpProQuiz_Model_Quiz::QUIZ_TOPLIST_SORT_NEW: $s = 'ORDER BY date DESC'; break; case WpProQuiz_Model_Quiz::QUIZ_TOPLIST_SORT_OLD: default: $s = 'ORDER BY date ASC'; break; } $results = $this->_wpdb->get_results( $this->_wpdb->prepare( 'SELECT * FROM '. $this->_tableToplist.' WHERE quiz_id = %d '.$s.' LIMIT %d, %d' , $quizId, $start, $limit), ARRAY_A); foreach($results as $row) { $r[] = new WpProQuiz_Model_Toplist($row); } return $r; } public function delete($quizId, $toplistIds = null) { $quizId = (int)$quizId; if($toplistIds === null) { return $this->_wpdb->delete($this->_tableToplist, array('quiz_id' => $quizId), array('%d')); } $ids = array_map('intval', (array)$toplistIds); return $this->_wpdb->query("DELETE FROM {$this->_tableToplist} WHERE quiz_id = {$quizId} AND toplist_id IN(".implode(', ', $ids).")"); } } lib/model/WpProQuiz_Model_Form.php 0000666 00000004764 15214236625 0013173 0 ustar 00 _formId = (int)$_formId; return $this; } public function getFormId() { return $this->_formId; } public function setQuizId($_quizId) { $this->_quizId = (int)$_quizId; return $this; } public function getQuizId() { return $this->_quizId; } public function setFieldname($_fieldname) { $this->_fieldname = (string)$_fieldname; return $this; } public function getFieldname() { return $this->_fieldname; } public function setType($_type) { $this->_type = (int)$_type; return $this; } public function getType() { return $this->_type; } public function setRequired($_required) { $this->_required = (bool)$_required; return $this; } public function isRequired() { return $this->_required; } public function setSort($_sort) { $this->_sort = (int)$_sort; return $this; } public function getSort() { return $this->_sort; } public function setData($_data) { $this->_data = $_data === null ? null : (array)$_data; return $this; } public function getData() { return $this->_data; } public function getValue( $form_data = '' ) { switch ( $this->getType() ) { case WpProQuiz_Model_Form::FORM_TYPE_TEXT: case WpProQuiz_Model_Form::FORM_TYPE_TEXTAREA: case WpProQuiz_Model_Form::FORM_TYPE_EMAIL: case WpProQuiz_Model_Form::FORM_TYPE_NUMBER: case WpProQuiz_Model_Form::FORM_TYPE_RADIO: case WpProQuiz_Model_Form::FORM_TYPE_SELECT: return esc_html( $form_data ); break; case WpProQuiz_Model_Form::FORM_TYPE_CHECKBOX: return $form_data == '1' ? esc_html__('ticked', 'learndash') : esc_html__('not ticked', 'learndash'); break; case WpProQuiz_Model_Form::FORM_TYPE_YES_NO: return $form_data == 1 ? esc_html__('Yes', 'learndash') : esc_html__('No', 'learndash'); break; case WpProQuiz_Model_Form::FORM_TYPE_DATE: return date_format( date_create( $form_data ), get_option( 'date_format' ) ); break; default: return $form_data; break; } } } lib/model/WpProQuiz_Model_StatisticMapper.php 0000666 00000006637 15214236625 0015405 0 ustar 00 _wpdb->get_results( $this->_wpdb->prepare( 'SELECT * FROM '. $this->_tableStatistic.' WHERE statistic_ref_id = %d', $statisticRefId), ARRAY_A); foreach($results as $row) { $a[] = new WpProQuiz_Model_Statistic($row); } return $a; } public function isStatisticByQuestionId($questionId) { return $this->_wpdb->get_var( $this->_wpdb->prepare( "SELECT COUNT(*) FROM {$this->_tableStatistic} WHERE question_id = %d", $questionId) ); } /* public function save($s) { $values = array(); if($s->getUserId()) { $refId = $this->_wpdb->get_var( $this->_wpdb->prepare(' SELECT statistic_ref_id FROM '.$this->_tableStatisticRef.' WHERE quiz_id = %d AND user_id = %d ', $quiz_id, $user_id) ); if($refId === null) { $this->_wpdb->insert($this->_tableStatisticRef, array( 'quiz_id' => 0, 'user_id' => 0, 'create_time' => 0, 'is_old' => 1 ), array( '%d', '%d', '%d', '%d' )); } } foreach($s as $d) { $values[] = '( '.implode(', ', array( 'quiz_id' => $d->getQuizId(), 'question_id' => $d->getQuestionId(), 'user_id' => $d->getUserId(), 'correct_count' => $d->getCorrectCount(), 'incorrect_count' => $d->getIncorrectCount(), 'hint_count' => $d->getHintCount(), 'points' => $d->getPoints() )).' )'; } $this->_wpdb->query( 'INSERT INTO '.$this->_tableStatistic.' ( quiz_id, question_id, user_id, correct_count, incorrect_count, hint_count, points ) VALUES '.implode(', ', $values).' ON DUPLICATE KEY UPDATE correct_count = correct_count + VALUES(correct_count), incorrect_count = incorrect_count + VALUES(incorrect_count), hint_count = hint_count + VALUES(hint_count), points = points + VALUES(points)' ); } */ /* public function save($quizId, $userId, $array) { $ids = $this->_wpdb->get_col($this->_wpdb->prepare("SELECT id FROM {$this->_tableQuestion} WHERE quiz_id = %d", $quizId)); $ak = array_keys($array); if(array_diff($ids, $ak) !== array_diff($ak, $ids)) return false; $values = array(); $globalValue = array( 'quiz_id' => $quizId, 'question_id' => 0, 'user_id' => $userId, 'correct_count' => 0, 'incorrect_count' => 0, 'hint_count' => 0, 'correct_answer_count' => 0 ); foreach($array as $k => $v) { $value = $globalValue; $value['question_id'] = $k; if(isset($v['tip'])) { $value['hint_count'] = 1; } if($v['correct']) { $value['correct_count'] = 1; } else { $value['incorrect_count'] = 1; } $value['correct_answer_count'] = isset($v['correct_answer_count']) ? (int)$v['correct_answer_count'] : 0; $values[] = '('.implode(', ', $value).')'; } $this->_wpdb->query( 'INSERT INTO '.$this->_tableStatistic.' ('.implode(', ', array_keys($globalValue)).') VALUES '.implode(', ', $values).' ON DUPLICATE KEY UPDATE correct_count = correct_count + VALUES(correct_count), incorrect_count = incorrect_count + VALUES(incorrect_count), hint_count = hint_count + VALUES(hint_count), correct_answer_count = correct_answer_count + VALUES(correct_answer_count)' ); } */ } lib/model/WpProQuiz_Model_Question.php 0000666 00000023604 15214236625 0014071 0 ustar 00 _id = (int) $_id; return $this; } public function getId() { return $this->_id; } public function setQuestionPostId( $question_post_id = 0 ) { $this->_questionPostId = absint( $question_post_id ); } public function getQuestionPostId() { return $this->_questionPostId; } public function setQuizId( $_quizId ) { $this->_quizId = (int) $_quizId; return $this; } public function getQuizId() { return $this->_quizId; } public function setSort( $_sort ) { $this->_sort = (int) $_sort; return $this; } public function getSort() { return $this->_sort; } public function setTitle( $_title ) { $this->_title = (string) $_title; return $this; } public function getTitle() { return $this->_title; } public function setQuestion( $_question ) { $this->_question = (string) $_question; return $this; } public function getQuestion() { return $this->_question; } public function setCorrectMsg( $_correctMsg ) { $this->_correctMsg = (string) $_correctMsg; return $this; } public function getCorrectMsg() { return $this->_correctMsg; } public function setIncorrectMsg( $_incorrectMsg ) { $this->_incorrectMsg = (string) $_incorrectMsg; return $this; } public function getIncorrectMsg() { if ( $this->_correctSameText == true ) return $this->_correctMsg; else return $this->_incorrectMsg; } public function setAnswerType( $_answerType ) { $this->_answerType = (string) $_answerType; return $this; } public function getAnswerType() { return $this->_answerType; } public function setCorrectSameText( $_correctSameText ) { $this->_correctSameText = (bool) $_correctSameText; return $this; } public function isCorrectSameText() { return $this->_correctSameText; } public function setTipEnabled( $_tipEnabled ) { $this->_tipEnabled = (bool) $_tipEnabled; return $this; } public function isTipEnabled() { return $this->_tipEnabled; } public function setTipMsg( $_tipMsg ) { $this->_tipMsg = (string) $_tipMsg; return $this; } public function getTipMsg() { return $this->_tipMsg; } public function setPoints( $_points ) { $this->_points = (int) $_points; return $this; } public function getPoints() { return $this->_points; } public function setShowPointsInBox( $_showPointsInBox ) { $this->_showPointsInBox = (bool) $_showPointsInBox; return $this; } public function isShowPointsInBox() { return $this->_showPointsInBox; } public function setAnswerPointsActivated( $_answerPointsActivated ) { $this->_answerPointsActivated = (bool) $_answerPointsActivated; return $this; } public function isAnswerPointsActivated() { return $this->_answerPointsActivated; } public function setAnswerData( $_answerData ) { $this->_answerData = $_answerData; return $this; } public function getAnswerData( $serialize = false ) { global $wpdb; if ( ! is_null( $this->_answerData ) ) { if ( ! is_array( $this->_answerData ) ) { $answerData = @maybe_unserialize( $this->_answerData ); if ( false === $answerData ) { $answerData = learndash_recount_serialized_bytes( $this->_answerData ); if ( false !== $answerData ) { $answerData = @maybe_unserialize( $answerData ); if ( false === $answerData ) { return null; } } } if ( ( ! empty( $answerData ) ) && ( is_array( $answerData ) ) ) { $changes = false; foreach ( $answerData as $a_idx => $answer ) { if ( ! is_a( $answer, 'WpProQuiz_Model_AnswerTypes' ) ) { $answer_model = learndash_cast_WpProQuiz_Model_AnswerTypes( $answer, 'WpProQuiz_Model_AnswerTypes' ); if ( ! is_a( $answer_model, 'WpProQuiz_Model_AnswerTypes' ) ) { continue; } $changes = true; $answerData[ $a_idx ] = $answer_model; } } if ( true === $changes ) { $wpdb->update( LDLMS_DB::get_table_name( 'quiz_question' ), array( 'answer_data' => serialize( $answerData ), ), array( 'id' => $this->_id, ), array( '%s' ), array( '%d' ) ); } } $this->_answerData = $answerData; } } /* if ( $this->_answerData === null ) { return null; } if ( is_array( $this->_answerData ) || $this->_answerData instanceof WpProQuiz_Model_AnswerTypes ) { if ( $serialize ) { return @serialize( $this->_answerData ); } } else { if ( ! $serialize ) { if ( WpProQuiz_Helper_Until::saveUnserialize( $this->_answerData, $into ) === false ) { return null; } $this->_answerData = $into; } } */ if ( $serialize ) { return @serialize( $this->_answerData ); } else { return $this->_answerData; } } public function setCategoryId( $_categoryId ) { $this->_categoryId = (int) $_categoryId; return $this; } public function getCategoryId() { return $this->_categoryId; } public function setCategoryName( $_categoryName ) { $this->_categoryName = (string) $_categoryName; return $this; } public function getCategoryName() { return $this->_categoryName; } public function setAnswerPointsDiffModusActivated( $_answerPointsDiffModusActivated ) { $this->_answerPointsDiffModusActivated = (bool) $_answerPointsDiffModusActivated; return $this; } public function isAnswerPointsDiffModusActivated() { return $this->_answerPointsDiffModusActivated; } public function setDisableCorrect( $_disableCorrect ) { $this->_disableCorrect = (bool) $_disableCorrect; return $this; } public function isDisableCorrect() { return $this->_disableCorrect; } public function setMatrixSortAnswerCriteriaWidth( $_matrixSortAnswerCriteriaWidth ) { $this->_matrixSortAnswerCriteriaWidth = (int) $_matrixSortAnswerCriteriaWidth; return $this; } public function getMatrixSortAnswerCriteriaWidth() { return $this->_matrixSortAnswerCriteriaWidth; } public function get_object_as_array() { $object_vars = array( '_id' => $this->getId(), '_quizId' => $this->getQuizId(), '_sort' => $this->getSort(), '_title' => $this->getTitle(), '_question' => $this->getQuestion(), '_correctMsg' => $this->getCorrectMsg(), '_incorrectMsg' => $this->getIncorrectMsg(), '_correctSameText' => $this->isCorrectSameText(), '_tipEnabled' => $this->isTipEnabled(), '_tipMsg' => $this->getTipMsg(), '_points' => $this->getPoints(), '_showPointsInBox' => $this->isShowPointsInBox(), '_answerPointsActivated' => $this->isAnswerPointsActivated(), '_answerType' => $this->getAnswerType(), '_answerData' => $this->getAnswerData(), '_answerPointsDiffModusActivated' => $this->isAnswerPointsDiffModusActivatedfalse(), '_disableCorrect' => $this->isDisableCorrect(), '_matrixSortAnswerCriteriaWidth' => $this->getMatrixSortAnswerCriteriaWidth(), ); return $object_vars; } public function set_array_to_object( $array_vars = array() ) { foreach( $array_vars as $key => $value ) { switch( $key ) { case '_quizId': $this->setQuizId( $value ); break; case '_sort': $this->setSort( $value ); break; case '_title': $this->setTitle( $value ); break; case '_question': $this->setQuestion( $value ); break; case '_correctMsg': $this->setCorrectMsg( $value ); break; case '_incorrectMsg': $this->setIncorrectMsg( $value ); break; case '_answerType': $this->setAnswerType( $value ); break; case '_answerData': if ( is_array( $value ) ) { $answer_import_array = array(); foreach( $value as $answer_item ) { if ( is_array( $answer_item ) ) { $answer_import = new WpProQuiz_Model_AnswerTypes(); $answer_import->set_array_to_object( $answer_item ); $answer_import_array[] = $answer_import; } else if ( is_a($answer_item, 'WpProQuiz_Model_AnswerTypes' ) ) { $answer_import_array[] = $answer_item; } } //if ( !empty( $answer_import_array ) ) { $this->setAnswerData( $answer_import_array ); //} } break; case '_correctSameText': $this->setCorrectSameText( $value ); break; case '_tipEnabled': $this->setTipEnabled( $value ); break; case '_tipMsg': $this->setTipMsg( $value ); break; case '_points': $this->setPoints( $value ); break; case '_showPointsInBox': $this->setShowPointsInBox( $value ); break; case '_answerPointsActivated': $this->setAnswerPointsActivated( $value ); break; case '_categoryId': $this->setCategoryId( $value ); break; case '_categoryName': $this->setCategoryName( $value ); break; case '_answerPointsDiffModusActivated': $this->setAnswerPointsDiffModusActivated( $value ); break; case '_disableCorrect': $this->setDisableCorrect( $value ); break; case '_matrixSortAnswerCriteriaWidth': $this->setMatrixSortAnswerCriteriaWidth( $value ); break; default: break; } } } } lib/model/WpProQuiz_Model_TemplateMapper.php 0000666 00000003642 15214236625 0015202 0 ustar 00 _wpdb->replace($this->_tableTemplate, array( 'template_id' => $template->getTemplateId(), 'name' => $template->getName(), 'type' => $template->getType(), 'data' => @serialize($template->getData()) ), array('%d', '%s', '%d', '%s')); $template->setTemplateId($this->getInsertId()); return $template; } public function updateName($templateId, $name) { return $this->_wpdb->update($this->_tableTemplate, array( 'name' => $name ), array( 'template_id' => $templateId ), array('%s'), array('%d')); } public function delete($templateId) { return $this->_wpdb->delete($this->_tableTemplate, array('template_id' => $templateId), array('%d')); } public function fetchAll($type, $loadData = true) { $r = array(); $result = $this->_wpdb->get_results($this->_wpdb->prepare( "SELECT * FROM {$this->_tableTemplate} WHERE type = %d AND name != '' ORDER BY name ASC" , $type), ARRAY_A); foreach($result as $row) { $data = $row['data']; unset($row['data']); $template = new WpProQuiz_Model_Template($row); if($loadData && WpProQuiz_Helper_Until::saveUnserialize($data, $into)) { $template->setData($into); } $r[] = $template; } return $r; } public function fetchById($templateId, $loadData = true) { $row = $this->_wpdb->get_row($this->_wpdb->prepare( "SELECT * FROM {$this->_tableTemplate} WHERE template_id = %d " , $templateId), ARRAY_A); if($row !== null) { $data = $row['data']; unset($row['data']); $template = new WpProQuiz_Model_Template($row); if($loadData && WpProQuiz_Helper_Until::saveUnserialize($data, $into)) { $template->setData($into); } return $template; } return new WpProQuiz_Model_Template(); } } lib/model/WpProQuiz_Model_PrerequisiteMapper.php 0000666 00000004755 15214236625 0016116 0 ustar 00 delete( $this->_tablePrerequisite, array('prerequisite_quiz_id' => $prerequisiteQuizId), array('%d') ); } public function isQuizId($quizId) { return $this->_wpdb->get_var( $this->_wpdb->prepare("SELECT (quiz_id) FROM {$this->_tablePrerequisite} WHERE quiz_id = %d", $quizId) ); } public function fetchQuizIds($prerequisiteQuizId) { $sql_str = $this->_wpdb->prepare( "SELECT quiz_id FROM {$this->_tablePrerequisite} WHERE prerequisite_quiz_id = %d", $prerequisiteQuizId); $quiz_pro_ids = $this->_wpdb->get_col( $sql_str ); if ( ! empty( $quiz_pro_ids ) ) { $sql_str = "SELECT postmeta.meta_value as quiz_pro_id FROM {$this->_wpdb->posts} AS posts INNER JOIN {$this->_wpdb->postmeta} as postmeta ON posts.ID = postmeta.post_id WHERE posts.post_type='". learndash_get_post_type_slug( 'quiz' ) . "' AND posts.post_status = 'publish' AND postmeta.meta_key='quiz_pro_id' AND postmeta.meta_value IN ( ". implode( ',', $quiz_pro_ids ) . " )"; $quiz_pro_ids = $this->_wpdb->get_col( $sql_str ); if ( ! empty( $quiz_pro_ids ) ) { $quiz_pro_ids = array_map( 'intval', $quiz_pro_ids ); $quiz_pro_ids = array_unique( $quiz_pro_ids ); } } return ( array ) $quiz_pro_ids; } public function save($prerequisiteQuizId, $quiz_ids) { foreach($quiz_ids as $quiz_id) { $this->_wpdb->insert($this->_tablePrerequisite, array( 'prerequisite_quiz_id' => $prerequisiteQuizId, 'quiz_id' => $quiz_id ), array('%d', '%d')); } } public function getNoPrerequisite($prerequisiteQuizId, $userId) { if ( ( defined( 'LEARNDASH_QUIZ_PREREQUISITE_ALT' ) ) && ( LEARNDASH_QUIZ_PREREQUISITE_ALT === true ) ) { $sql_str = $this->_wpdb->prepare( "SELECT p.quiz_id FROM {$this->_tablePrerequisite} AS p WHERE p.prerequisite_quiz_id = %d", $prerequisiteQuizId ); $prereq_quiz_ids = $this->_wpdb->get_col( $sql_str ); return $prereq_quiz_ids; } else { return $this->_wpdb->get_col( $this->_wpdb->prepare( "SELECT p.quiz_id FROM {$this->_tablePrerequisite} AS p LEFT JOIN {$this->_tableStatisticRef} AS s ON ( s.quiz_id = p.quiz_id AND s.user_id = %d ) WHERE s.user_id IS NULL AND p.prerequisite_quiz_id = %d GROUP BY p.quiz_id", $userId, $prerequisiteQuizId) ); } } } lib/model/WpProQuiz_Model_CategoryMapper.php 0000666 00000007527 15214236625 0015212 0 ustar 00 _wpdb->get_results("SELECT * FROM {$this->_tableCategory}", ARRAY_A); foreach ($results as $row) { $r[] = new WpProQuiz_Model_Category($row); } return $r; } public function fetchByQuiz( $quizId ) { $r = array(); if ( is_a( $quizId, 'WpProQuiz_Model_Quiz' ) ) { $quiz = $quizId; $quizId = $quiz->getId(); if ( empty( $quiz_post_id ) ) { $quiz_post_id = $quiz->getPostId(); } } if ( ( ! empty( $quiz_post_id ) ) && ( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Builder', 'enabled' ) === 'yes' ) && ( true === is_data_upgrade_quiz_questions_updated() ) ) { $ld_quiz_questions_object = LDLMS_Factory_Post::quiz_questions( intval( $quiz_post_id ) ); if ( $ld_quiz_questions_object ) { $quiz_questions = $ld_quiz_questions_object->get_questions(); if ( ! empty( $quiz_questions ) ) { $cat_sql_str = 'SELECT c.* FROM ' . $this->_tableCategory . ' AS c RIGHT JOIN ' . $this->_tableQuestion . ' AS q ON c.category_id = q.category_id WHERE q.id IN ('. implode( ',', $quiz_questions ) . ') GROUP BY q.category_id ORDER BY c.category_name'; $results = $this->_wpdb->get_results( $cat_sql_str, ARRAY_A ); } } } else { $results = $this->_wpdb->get_results($this->_wpdb->prepare(' SELECT c.* FROM '.$this->_tableCategory.' AS c RIGHT JOIN '.$this->_tableQuestion.' AS q ON c.category_id = q.category_id WHERE q.quiz_id = %d GROUP BY q.category_id ORDER BY c.category_name ', $quizId), ARRAY_A); } foreach($results as $row) { $r[] = new WpProQuiz_Model_Category($row); } return $r; } public function save(WpProQuiz_Model_Category $category) { $data = array('category_name' => $category->getCategoryName()); $format = array('%s'); if($category->getCategoryId() == 0) { $this->_wpdb->insert($this->_tableCategory, $data, $format); $category->setCategoryId($this->_wpdb->insert_id); } else { $this->_wpdb->update( $this->_tableCategory, $data, array('category_id' => $category->getCategoryId()), $format, array('%d')); } return $category; } public function updateCatgoryName($categoryId, $name) { return $this->_wpdb->update( $this->_tableCategory, array( 'category_name' => $name ), array( 'category_id' => $categoryId ), array('%s'), array('%d') ); } public function delete($categoryId) { $this->_wpdb->update($this->_tableQuestion, array('category_id' => 0), array('category_id' => $categoryId), array('%d'), array('%d')); return $this->_wpdb->delete($this->_tableCategory, array('category_id' => $categoryId), array('%d')); } public function getCategoryArrayForImport() { $r = array(); $results = $this->_wpdb->get_results("SELECT * FROM {$this->_tableCategory}", ARRAY_A); foreach ($results as $row) { $r[strtolower($row['category_name'])] = (int)$row['category_id']; } return $r; } public function fetchById($categoryId, $loadData = true) { $row = $this->_wpdb->get_row( $this->_wpdb->prepare( "SELECT * FROM {$this->_tableCategory} WHERE category_id = %d ", $categoryId ), ARRAY_A ); if ( $row !== null ) { $category = new WpProQuiz_Model_Category( $row ); return $category; } return new WpProQuiz_Model_Category(); } public function fetchByName( $categoryName = '' ) { if ( ! empty( $categoryName ) ) { $row = $this->_wpdb->get_row( $this->_wpdb->prepare( "SELECT * FROM {$this->_tableCategory} WHERE category_name = %s ", $categoryName ), ARRAY_A ); if ( $row !== null ) { $category = new WpProQuiz_Model_Category( $row ); return $category; } } return new WpProQuiz_Model_Category(); } } lib/model/WpProQuiz_Model_Model.php 0000666 00000002470 15214236625 0013320 0 ustar 00 setModelData($array); } public function setModelData($array) { if($array != null) { // foreach($array as $k => $v) { // if(strpos($k, '_') !== false) { // // $k = str_replace(' ', '', ucwords(str_replace('_', ' ', $k))); // $k = implode('', array_map('ucfirst', explode('_', $k))); // } else { // $k = ucfirst($k); // } // // $this->{'set'.ucfirst($k)}($v); // $this->{'set'.$k}($v); // } //3,4x faster $n = explode(' ', implode('', array_map('ucfirst', explode('_', implode(' _', array_keys($array)))))); $a = array_combine($n, $array); if (isset($a['Id'])) { $this->setId($a['Id']); } foreach($a as $k => $v) { $this->{'set'.$k}($v); } } } public function __call($name, $args) { } /** * * @return WpProQuiz_Model_QuizMapper */ public function getMapper() { if($this->_mapper === null) { $this->_mapper = new WpProQuiz_Model_QuizMapper(); } return $this->_mapper; } /** * @param WpProQuiz_Model_QuizMapper $mapper * @return WpProQuiz_Model_Model */ public function setMapper($mapper) { $this->_mapper = $mapper; return $this; } } lib/model/WpProQuiz_Model_StatisticHistory.php 0000666 00000005341 15214236625 0015611 0 ustar 00 _userId = (int)$_userId; return $this; } public function getUserId() { return $this->_userId; } public function setUserName($_userName) { $this->_userName = (string)$_userName; return $this; } public function getUserName() { return $this->_userName; } public function setStatisticRefId($_statisticRefId) { $this->_statisticRefId = (int)$_statisticRefId; return $this; } public function getStatisticRefId() { return $this->_statisticRefId; } public function setQuizId($_quizId) { $this->_quizId = (int)$_quizId; return $this; } public function getQuizId() { return $this->_quizId; } public function setCreateTime($_createTime) { $this->_createTime = (int)$_createTime; return $this; } public function getCreateTime() { return $this->_createTime; } public function setCorrectCount($_correctCount) { $this->_correctCount = (int)$_correctCount; return $this; } public function getCorrectCount() { return $this->_correctCount; } public function setIncorrectCount($_incorrectCount) { $this->_incorrectCount = (int)$_incorrectCount; return $this; } public function getIncorrectCount() { return $this->_incorrectCount; } public function setPoints($_points) { $this->_points = (int)$_points; return $this; } public function getPoints() { return $this->_points; } public function setResult($_result) { $this->_result = (float)$_result; return $this; } public function getResult() { return $this->_result; } public function setFormatTime($_formatTime) { $this->_formatTime = (string)$_formatTime; return $this; } public function getFormatTime() { return $this->_formatTime; } public function setFormatCorrect($_formatCorrect) { $this->_formatCorrect = (string)$_formatCorrect; return $this; } public function getFormatCorrect() { return $this->_formatCorrect; } public function setFormatIncorrect($_formatIncorrect) { $this->_formatIncorrect = (string)$_formatIncorrect; return $this; } public function getFormatIncorrect() { return $this->_formatIncorrect; } public function setGPoints($_gPoints) { $this->_gPoints = (int)$_gPoints; return $this; } public function getGPoints() { return $this->_gPoints; } } lib/model/WpProQuiz_Model_FormMapper.php 0000666 00000003403 15214236625 0014325 0 ustar 00 _wpdb->query( $this->_wpdb->prepare(' DELETE FROM '.$this->_tableForm.' WHERE form_id IN('.implode(', ', array_map('intval', (array)$formIds)).') AND quiz_id = %d ', $quizId) ); } /** * @param WpProQuiz_Model_Form $forms */ public function update($forms) { $values = $values2 = array(); foreach($forms as $form) { /* @var $form WpProQuiz_Model_Form */ $data = array( $form->getFormId(), $form->getQuizId(), $form->getFieldname(), $form->getType(), (int)$form->isRequired(), $form->getSort() ); if($form->getData() === null) { $values[] = '('. $this->_wpdb->prepare('%d, %d, %s, %d, %d, %d', $data).')'; } else { $data[] = @json_encode($form->getData()); $values2[] = '('. $this->_wpdb->prepare('%d, %d, %s, %d, %d, %d, %s', $data).')'; } } if(!empty($values)) { $this->_wpdb->query(' REPLACE INTO '.$this->_tableForm.' (form_id, quiz_id, fieldname, type, required, sort) VALUES '.implode(', ', $values).' '); } if(!empty($values2)) { $this->_wpdb->query(' REPLACE INTO '.$this->_tableForm.' (form_id, quiz_id, fieldname, type, required, sort, data) VALUES '.implode(', ', $values2).' '); } } public function fetch($quizId) { $results = $this->_wpdb->get_results( $this->_wpdb->prepare(' SELECT * FROM '.$this->_tableForm.' WHERE quiz_id = %d ORDER BY sort', $quizId), ARRAY_A); $a = array(); foreach($results as $row) { $row['data'] = $row['data'] === null ? null : @json_decode($row['data'], true); $a[] = new WpProQuiz_Model_Form($row); } return $a; } } lib/model/WpProQuiz_Model_StatisticUserMapper.php 0000666 00000003300 15214236625 0016224 0 ustar 00 _wpdb->get_results( $this->_wpdb->prepare( "SELECT SUM(s.correct_count) AS correct_count, SUM(s.incorrect_count) AS incorrect_count, SUM(s.hint_count) AS hint_count, SUM(s.points) AS points, AVG(s.question_time) AS question_time, s.answer_data AS statistic_answer_data, q.id AS question_id, q.". apply_filters('ld_fetchUserStatistic_question_title', 'question')." AS question_name, q.answer_data AS question_answer_data, q.answer_type, SUM(q.points * (s.correct_count + s.incorrect_count)) AS g_points, c.category_id, c.category_name FROM {$this->_tableStatisticRef} AS sf INNER JOIN {$this->_tableStatistic} AS s ON(s.statistic_ref_id = sf.statistic_ref_id) INNER JOIN {$this->_tableQuestion} AS q ON(q.id = s.question_id) LEFT JOIN {$this->_tableCategory} AS c ON(c.category_id = q.category_id) WHERE {$where} AND sf.quiz_id = %d GROUP BY s.question_id ORDER BY ISNULL(c.category_name), c.category_name, q.sort", $refIdUserId, $quizId), ARRAY_A); $r = array(); foreach($result as $row) { if(!$avg) { if($row['statistic_answer_data'] !== null) { $row['statistic_answer_data'] = json_decode($row['statistic_answer_data'], true); } } else { $row['statistic_answer_data'] = null; $row['question_answer_data'] = null; } $r[] = new WpProQuiz_Model_StatisticUser($row); } return $r; } } lib/plugin/WpProQuiz_Plugin_BpAchievementsV2.php 0000666 00000003237 15214236625 0015763 0 ustar 00 get_var("SHOW TABLES LIKE '{$wpdb->prefix}achievements_actions'") === null) return false; $actions = array( array( 'category' => 'Wp-Pro-Quiz', 'name' => 'wp_pro_quiz_quiz_finished', 'description' => sprintf( esc_html_x('The user completed a %s.', 'The user completed a quiz.', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ) ) ); foreach($actions as $action) { if($wpdb->get_var("SELECT id FROM {$wpdb->prefix}achievements_actions WHERE name = 'wp_pro_quiz_quiz_finished'") === null) $wpdb->insert($wpdb->prefix.'achievements_actions', $action); } return true; } public static function deinstall() { global $wpdb; if($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}achievements_actions'") === null) return false; $wpdb->delete($wpdb->prefix.'achievements_actions', array('name' => 'wp_pro_quiz_quiz_finished')); } } function dpa_handle_action_wp_pro_quiz_quiz_finished() { $func_get_args = func_get_args(); dpa_handle_action('wp_pro_quiz_quiz_finished', $func_get_args); } lib/plugin/WpProQuiz_Plugin_BpAchievementsV3.php 0000666 00000003320 15214236625 0015755 0 ustar 00 actions = array( 'wp_pro_quiz_completed_quiz' => sprintf( esc_html_x('The user completed a %s.', 'The user completed a quiz.', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ), 'wp_pro_quiz_completed_quiz_100_percent' => sprintf( esc_html_x('The user completed a %s with 100 percent.', 'The user completed a quiz with 100 percent.', 'learndash'), learndash_get_custom_label_lower( 'quiz' )), ); $this->contributors = array( array( 'name' => 'Julius Fischer', 'gravatar_url' => 'http://gravatar.com/avatar/c3736cd18c273f32569726c93f76244d', 'profile_url' => 'http://profiles.wordpress.org/xeno010', ) ); $this->description = sprintf( esc_html_x('A powerful and beautiful %s plugin for WordPress.', 'A powerful and beautiful quiz plugin for WordPress.', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ); $this->id = 'wp-pro-quiz'; $this->image_url = WPPROQUIZ_URL.'/img/wp_pro_quiz.jpg'; $this->name = esc_html__( 'WP-Pro-Quiz', 'learndash' ); //$this->rss_url = ''; $this->small_image_url = WPPROQUIZ_URL.'/img/wp_pro_quiz_small.jpg'; $this->version = 5; $this->wporg_url = 'http://wordpress.org/extend/plugins/wp-pro-quiz/'; } public function do_update($current_version) { $this->insertTerm(); } public function insertTerm() { $taxId = dpa_get_event_tax_id(); foreach ($this->actions as $actionName => $desc) { $e = term_exists($actionName, $taxId); if($e === 0 || $e === null) { wp_insert_term($actionName, $taxId, array('description' => $desc)); } } } } lib/controller/WpProQuiz_Controller_Toplist.php 0000666 00000026411 15214236625 0016065 0 ustar 00 loadToplist($quizId); break; case 'show': default: $this->showAdminToplist($quizId); break; } } private function loadToplist($quizId) { if(!current_user_can('wpProQuiz_toplist_edit')) { echo json_encode(array()); return; } $toplistMapper = new WpProQuiz_Model_ToplistMapper(); $j = array('data' => array()); $limit = (int)$this->_post['limit']; $start = $limit * ($this->_post['page'] - 1); $isNav = isset($this->_post['nav']); if(isset($this->_post['a'])) { switch ($this->_post['a']) { case 'deleteAll': $toplistMapper->delete($quizId); break; case 'delete': if(!empty($this->_post['toplistIds'])) $toplistMapper->delete($quizId, $this->_post['toplistIds']); break; } $start = 0; $isNav = true; } $toplist = $toplistMapper->fetch($quizId, $limit, $this->_post['sort'], $start); foreach($toplist as $tp) { $j['data'][] = array( 'id' => $tp->getToplistId(), 'name' => $tp->getName(), 'email' => $tp->getEmail(), 'type' => $tp->getUserId() ? 'R' : 'UR', 'date' => WpProQuiz_Helper_Until::convertTime( $tp->getDate(), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Management_Display', 'toplist_time_format' ) //get_option('wpProQuiz_toplistDataFormat', 'Y/m/d g:i A') ), 'points' => $tp->getPoints(), 'result' => $tp->getResult() ); } if($isNav) { $count = $toplistMapper->count($quizId); $pages = ceil($count / $limit); $j['nav'] = array( 'count' => $count, 'pages' => $pages ? $pages : 1 ); } echo json_encode($j); } private function editAdminToplist() { $toplistId = $this->_post['toplistId']; $username = trim($this->_post['name']); $email = trim($this->_post['email']); if(empty($name) || empty($email) || filter_var($email, FILTER_VALIDATE_EMAIL) === false) { return array('error' => esc_html__('No name or e-mail entered.', 'learndash')); } } private function showAdminToplist($quizId) { if(!current_user_can('wpProQuiz_toplist_edit')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $view = new WpProQuiz_View_AdminToplist(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $quiz = $quizMapper->fetch($quizId); $view->quiz = $quiz; $view->show(); } public function getAddToplist(WpProQuiz_Model_Quiz $quiz) { $userId = get_current_user_id(); if(!$quiz->isToplistActivated()) return null; $data = array( 'userId' => $userId, 'token' => wp_create_nonce('wpProQuiz_toplist'), 'canAdd' => $this->preCheck($quiz->getToplistDataAddPermissions(), $userId), ); if($quiz->isToplistDataCaptcha() && $userId == 0) { $captcha = WpProQuiz_Helper_Captcha::getInstance(); if($captcha->isSupported()) { $data['captcha']['img'] = WPPROQUIZ_CAPTCHA_URL.'/'.$captcha->createImage(); $data['captcha']['code'] = $captcha->getPrefix(); } } return $data; } public function addInToplist() { if ( is_user_logged_in() ) { $user_id = get_current_user_id(); } else { $user_id = 0; } $include_admin_in_reports = true; if ( !empty( $user_id ) ) { if ( learndash_is_admin_user( $user_id ) ) { $include_admin_in_reports = LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Section_General_Admin_User', 'reports_include_admin_users' ); if ( $include_admin_in_reports == 'yes' ) $include_admin_in_reports = true; else $include_admin_in_reports = false; } else { $include_admin_in_reports = true; } // For logged in users to allow an override filter. $include_admin_in_reports = apply_filters( 'learndash_quiz_add_toplist_bypass', $include_admin_in_reports, $user_id, $this->_post ); } if ( $include_admin_in_reports ) { $quizId = isset($this->_post['quizId']) ? $this->_post['quizId'] : 0; $prefix = !empty($this->_post['prefix']) ? trim($this->_post['prefix']) : ''; $quizMapper = new WpProQuiz_Model_QuizMapper(); $quiz = $quizMapper->fetch($quizId); $r = $this->handleAddInToplist($quiz); if($quiz->isToplistActivated() && $quiz->isToplistDataCaptcha() && get_current_user_id() == 0) { $captcha = WpProQuiz_Helper_Captcha::getInstance(); if($captcha->isSupported()) { $captcha->remove($prefix); $captcha->cleanup(); if($r !== true) { $r['captcha']['img'] = WPPROQUIZ_CAPTCHA_URL.'/'.$captcha->createImage(); $r['captcha']['code'] = $captcha->getPrefix(); } } } } else { $r = true; } if ( $r === true) { $r = array( 'text' => esc_html__( 'You signed up successfully.', 'learndash' ), 'clear' => true ); } echo json_encode($r); } private function handleAddInToplist(WpProQuiz_Model_Quiz $quiz) { if(!wp_verify_nonce($this->_post['token'], 'wpProQuiz_toplist')) { return array('text' => esc_html__('An error has occurred.', 'learndash'), 'clear' => true); } //if(!isset($this->_post['points']) || !isset($this->_post['totalPoints'])) { // return array('text' => esc_html__('An error has occurred.', 'learndash'), 'clear' => true); //} $quizId = $quiz->getId(); $userId = get_current_user_id(); $quiz_post_id = (int)$this->_post['quiz']; //$points = (int)$this->_post['points']; // Added v2.4.3 to validate the comp points with nonce. See ld-quiz-pro.php checkAnswers() for nonce definition logic. //if ( !wp_verify_nonce($this->_post['p_nonce'], 'ld_quiz_pnonce'. $userId .'_'. $quizId .'_'. $quiz_post_id .'_'. 'comp' .'_'. $points) ) { // return array('text' => esc_html__('An error has occurred.', 'learndash'), 'clear' => true); //} if ( !isset( $this->_post['results']) ) { return array('text' => esc_html__('An error has occurred.', 'learndash'), 'clear' => true); } $results = $this->_post['results']; if ( !empty( $results ) ) { $total_possible_points = 0; $total_awarded_points = 0; foreach( $results as $r_idx => $result ) { if ( $r_idx == 'comp' ) { $points = intval( $total_awarded_points ); continue; } $points_array = array( 'points' => intval( $result['points'] ), 'correct' => intval( $result['correct'] ), 'possiblePoints' => intval( $result['possiblePoints'] ) ); if ( $points_array['correct'] === false ) $points_array['correct'] = 0; else if ( $points_array['correct'] === true ) $points_array['correct'] = 1; $points_str = maybe_serialize( $points_array ); if ( !wp_verify_nonce( $result['p_nonce'], 'ld_quiz_pnonce'. $userId .'_'. $quizId .'_'. $quiz_post_id .'_'. $r_idx .'_'. $points_str ) ) { $this->_post['results'][$r_idx]['points'] = 0; $this->_post['results'][$r_idx]['correct'] = 0; $this->_post['results'][$r_idx]['possiblePoints'] = 0; } $total_awarded_points += intval( $this->_post['results'][$r_idx]['points'] ); $total_possible_points += intval( $_POST['results'][$r_idx]['possiblePoints'] ); } } //$points = (int)$this->_post['points']; //$totalPoints = (int)$this->_post['totalPoints']; $name = !empty($this->_post['name']) ? trim($this->_post['name']) : ''; $email = !empty($this->_post['email']) ? trim($this->_post['email']) : ''; $ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); $captchaAnswer = !empty($this->_post['captcha']) ? trim($this->_post['captcha']) : ''; $prefix = !empty($this->_post['prefix']) ? trim($this->_post['prefix']) : ''; $quizMapper = new WpProQuiz_Model_QuizMapper(); $toplistMapper = new WpProQuiz_Model_ToplistMapper(); if($quiz == null || $quiz->getId() == 0 || !$quiz->isToplistActivated()) { return array('text' => esc_html__('An error has occurred.', 'learndash'), 'clear' => true); } if(!$this->preCheck($quiz->getToplistDataAddPermissions(), $userId)) { return array('text' => esc_html__('An error has occurred.', 'learndash'), 'clear' => true); } //$numPoints = $quizMapper->sumQuestionPoints($quizId); //$totalPoints = $quizMapper->sumQuestionPoints($quizId); //if($totalPoints > $numPoints || $points > $numPoints) { // return array('text' => esc_html__('An error has occurred.', 'learndash'), 'clear' => true); //} $clearTime = null; if($quiz->isToplistDataAddMultiple()) { $clearTime = $quiz->getToplistDataAddBlock() * 60; } if($userId > 0) { if($toplistMapper->countUser($quizId, $userId, $clearTime)) { return array('text' => esc_html__('You can not enter again.', 'learndash'), 'clear' => true); } $user = wp_get_current_user(); $email = $user->user_email; $name = $user->display_name; } else { if($toplistMapper->countFree($quizId, $name, $email, $ip, $clearTime)) { return array('text' => esc_html__('You can not enter again.', 'learndash'), 'clear' => true); } if(empty($name) || empty($email) || filter_var($email, FILTER_VALIDATE_EMAIL) === false) { return array('text' => esc_html__('No name or e-mail entered.', 'learndash'), 'clear' => false); } if(strlen($name) > 15) { return array('text' => esc_html__('Your name can not exceed 15 characters.', 'learndash'), 'clear' => false); } if($quiz->isToplistDataCaptcha()) { $captcha = WpProQuiz_Helper_Captcha::getInstance(); if($captcha->isSupported()) { if(!$captcha->check($prefix, $captchaAnswer)) { return array('text' => esc_html__('You entered wrong captcha code.', 'learndash'), 'clear' => false); } } } } $toplist = new WpProQuiz_Model_Toplist(); $toplist->setQuizId($quizId) ->setUserId($userId) ->setDate(time()) ->setName($name) ->setEmail($email) ->setPoints($points) ->setResult(round($points / $total_possible_points * 100, 2)) ->setIp($ip); $toplistMapper->save($toplist); return true; } private function preCheck($type, $userId) { switch($type) { case WpProQuiz_Model_Quiz::QUIZ_TOPLIST_TYPE_ALL: return true; case WpProQuiz_Model_Quiz::QUIZ_TOPLIST_TYPE_ONLY_ANONYM: return $userId == 0; case WpProQuiz_Model_Quiz::QUIZ_TOPLIST_TYPE_ONLY_USER: return $userId > 0; } return false; } public function showFrontToplist() { $quizIds = empty($this->_post['quizIds']) ? array() : array_unique((array)$this->_post['quizIds']); $toplistMapper = new WpProQuiz_Model_ToplistMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $r = array(); $j = array(); foreach($quizIds as $quizId) { $quiz = $quizMapper->fetch($quizId); if($quiz == null || $quiz->getId() == 0) continue; $toplist = $toplistMapper->fetch($quizId, $quiz->getToplistDataShowLimit(), $quiz->getToplistDataSort()); foreach($toplist as $tp) { $j[$quizId][] = array( 'name' => $tp->getName(), 'date' => WpProQuiz_Helper_Until::convertTime( $tp->getDate(), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Management_Display', 'toplist_time_format' ) //get_option('wpProQuiz_toplistDataFormat', 'Y/m/d g:i A') ), 'points' => $tp->getPoints(), 'result' => $tp->getResult() ); } } echo json_encode($j); } } lib/controller/WpProQuiz_Controller_Quiz.php 0000666 00000124436 15214236625 0015365 0 ustar 00 showAction(); break; case 'addEdit': $this->addEditQuiz($get, $post); break; case 'getEdit': return $this->getEditQuiz($get, $post); break; case 'addUpdateQuiz': return $this->addUpdateQuiz($get, $post); break; // case 'add': // $this->createAction(); // break; // case 'edit': // if(isset($_GET['id'])) // $this->editAction($get['id']); // break; case 'delete': if( isset( $get['id'] ) ) $this->deleteAction( intval( $get['id'] ) ); break; case 'reset_lock': if( isset($get['id'] ) ) $this->resetLock( intval( $get['id'] ) ); break; } } private function addEditQuiz($get = null, $post = null) { if(empty($get)) $get = $_GET; if(!empty($post)) $this->_post = $post; $quizId = isset($get['quizId']) ? (int)$get['quizId'] : 0; if($quizId) { if(!current_user_can('wpProQuiz_edit_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } } else { if(!current_user_can('wpProQuiz_add_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } } $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); $quiz = new WpProQuiz_Model_Quiz(); $forms = null; $prerequisiteQuizList = array(); if(!empty($get["post_id"])) { $quiz_post = get_post($get["post_id"]); if ( ( !empty( $quiz_post ) ) && ( is_a( $quiz_post, 'WP_Post' ) ) ) { $this->_post["name"] = $quiz_post->post_title; } } if($quizId && $quizMapper->exists($quizId) == 0) { WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s not found', 'Quiz not found', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ), 'error'); return; } if(isset($this->_post['template']) || (isset($this->_post['templateLoad']) && isset($this->_post['templateLoadId']))) { if(isset($this->_post['template'])) $template = $this->saveTemplate(); else $template = $templateMapper->fetchById($this->_post['templateLoadId']); $data = $template->getData(); if($data !== null) { $quiz = $data['quiz']; $quiz->setId($quizId); $quiz->setName($this->_post["name"]); $quiz->setText("AAZZAAZZ"); $quizMapper->save($quiz); if(empty($quizId) && !empty($get["post_id"])) { learndash_update_setting($get["post_id"], "quiz_pro", $quiz->getId()); } $quizId = $quiz->getId(); $forms = $data['forms']; $prerequisiteQuizList = $data['prerequisiteQuizList']; } } else if(isset($this->_post['form'])) { if(isset($this->_post['resultGradeEnabled'])) { $this->_post['result_text'] = $this->filterResultTextGrade($this->_post); } // Patch to only set Statistics on if post from form save. // LEARNDASH-1434 & LEARNDASH-1481 if ( !isset( $this->_post['statisticsOn'] ) ) { $this->_post['statisticsOn'] = '0'; $this->_post['viewProfileStatistics'] = '0'; } $quiz = new WpProQuiz_Model_Quiz($this->_post); $quiz->setId($quizId); if($this->checkValidit($this->_post)) { //if($quizId) // WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s edited', 'Quiz edited', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' )), 'info'); //else // WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s created', 'Quiz created', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' )), 'info'); $quiz->setText("AAZZAAZZ"); $quizMapper->save($quiz); if ( empty( $quizId ) && !empty( $get["post_id"] ) ) { learndash_update_setting($get["post_id"], "quiz_pro", $quiz->getId()); } //if ( ( isset( $get["post_id"] ) ) && ( !empty( $get["post_id"] ) ) ) { // if ( isset( $this->_post['viewProfileStatistics'] ) ) { // $quiz->setViewProfileStatistics( true ); // update_post_meta( $get["post_id"], '_viewProfileStatistics', 1 ); // } else { // $quiz->setViewProfileStatistics( false ); // update_post_meta( $get["post_id"], '_viewProfileStatistics', 0 ); // } //} $quizId = $quiz->getId(); $prerequisiteMapper->delete($quizId); if($quiz->isPrerequisite() && !empty($this->_post['prerequisiteList'])) { $prerequisiteMapper->save($quizId, $this->_post['prerequisiteList']); $quizMapper->activateStatitic($this->_post['prerequisiteList'], 1440); } if(!$this->formHandler($quiz->getId(), $this->_post)) { $quiz->setFormActivated(false); $quiz->setText("AAZZAAZZ"); $quizMapper->save($quiz); } $forms = $formMapper->fetch($quizId); $prerequisiteQuizList = $prerequisiteMapper->fetchQuizIds($quizId); } else { //WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s title or %s description are not filled', 'Quiz title or quiz description are not filled', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ), learndash_get_custom_label_lower( 'quiz' ))); } } else if($quizId) { $quiz = $quizMapper->fetch($quizId); $forms = $formMapper->fetch($quizId); $prerequisiteQuizList = $prerequisiteMapper->fetchQuizIds($quizId); } $this->view = new WpProQuiz_View_QuizEdit(); $this->view->quiz = $quiz; $this->view->forms = $forms; $this->view->prerequisiteQuizList = $prerequisiteQuizList; $this->view->templates = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false); $this->view->quizList = $quizMapper->fetchAllAsArray(array('id', 'name'), $quizId ? array($quizId) : array()); $this->view->captchaIsInstalled = class_exists('ReallySimpleCaptcha'); $this->view->header = $quizId ? sprintf( esc_html_x('Edit %s', 'Edit quiz', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ) : sprintf( esc_html_x('Create %s', 'Create quiz', 'learndash'), learndash_get_custom_label_lower( 'quiz' )); $this->view->show($get); } private function addUpdateQuiz( $get = null, $post = null ) { if( empty( $get ) ) $get = $_GET; if( ! empty( $post ) ) $this->_post = $post; $quizId = isset( $get['quizId'] ) ? (int)$get['quizId'] : 0; if( $quizId ) { if(!current_user_can('wpProQuiz_edit_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } } else { if(!current_user_can('wpProQuiz_add_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } } $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); $quiz = new WpProQuiz_Model_Quiz(); $forms = null; $prerequisiteQuizList = array(); if(!empty($get["post_id"])) { $quiz_post = get_post($get["post_id"]); if ( ( !empty( $quiz_post ) ) && ( is_a( $quiz_post, 'WP_Post' ) ) ) { $this->_post["name"] = $quiz_post->post_title; } } if( $quizId && $quizMapper->exists( $quizId ) == 0 ) { WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s not found', 'Quiz not found', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ), 'error'); return; } if ( ( ( isset( $this->_post['templateSaveList'] ) ) && ( intval( $this->_post['templateSaveList'] ) > 0 ) ) || ( ( isset( $this->_post['templateName'] ) ) && ( ! empty( $this->_post['templateName'] ) ) ) ) { $template = $this->saveTemplate(); } //if ( ( isset( $this->_post['templateName'] ) ) && ( ! empty( $this->_post['templateName'] ) ) ) { // $template = $this->saveTemplate(); //} if( isset( $this->_post['form'] ) ) { if( isset( $this->_post['resultGradeEnabled'] ) ) { $this->_post['result_text'] = $this->filterResultTextGrade( $this->_post ); } // Patch to only set Statistics on if post from form save. // LEARNDASH-1434 & LEARNDASH-1481 if ( !isset( $this->_post['statisticsOn'] ) ) { $this->_post['statisticsOn'] = '0'; $this->_post['viewProfileStatistics'] = '0'; } $quiz = new WpProQuiz_Model_Quiz( $this->_post ); $quiz->setId( $quizId ); if ( ! empty( $get['post_id'] ) ) { $quiz_post = get_post( $get['post_id'] ); if ( ( ! empty( $quiz_post ) ) && ( is_a( $quiz_post, 'WP_Post' ) ) ) { $quiz->setPostId = $quiz_post->ID; } } if( $this->checkValidit( $this->_post ) ) { //if( $quizId ) // WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s edited', 'Quiz edited', 'learndash' ), LearnDash_Custom_Label::get_label( 'quiz' ) ), 'info'); //else // WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s created', 'Quiz created', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' )), 'info'); $quiz->setText("AAZZAAZZ"); $quiz2 = $quizMapper->save($quiz); if ( ( empty( $quizId ) ) && ( isset( $get["post_id"] ) ) && ( !empty( $get["post_id"] ) ) ) { learndash_update_setting($get["post_id"], "quiz_pro", $quiz->getId()); $quiz_id_primary_new = absint( learndash_get_quiz_primary_shared( $quiz->getId(), false ) ); if ( empty( $quiz_id_primary_new ) ) { update_post_meta( $get["post_id"], 'quiz_pro_primary_'. $quiz->getId(), $quiz->getId() ); } } //if ( ( isset( $get["post_id"] ) ) && ( !empty( $get["post_id"] ) ) ) { // if ( isset( $this->_post['viewProfileStatistics'] ) ) { // $quiz->setViewProfileStatistics( true ); // update_post_meta( $get["post_id"], '_viewProfileStatistics', 1 ); // } else { // $quiz->setViewProfileStatistics( false ); // update_post_meta( $get["post_id"], '_viewProfileStatistics', 0 ); // } //} $quizId = $quiz->getId(); $prerequisiteMapper->delete($quizId); if($quiz->isPrerequisite() && !empty($this->_post['prerequisiteList'])) { $prerequisiteMapper->save($quizId, $this->_post['prerequisiteList']); $quizMapper->activateStatitic($this->_post['prerequisiteList'], 1440); } if(!$this->formHandler( $quiz->getId(), $this->_post ) ) { $quiz->setFormActivated( false ); $quiz->setText(" AAZZAAZZ" ); $quizMapper->save( $quiz ); } } else { //WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s title or %s description are not filled', 'Quiz title or quiz description are not filled', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ), learndash_get_custom_label_lower( 'quiz' ))); return false; } } } private function getEditQuiz($get = null, $post = null) { if(empty($get)) $get = $_GET; if(!empty($post)) $this->_post = $post; $quizId = isset($get['quizId']) ? (int)$get['quizId'] : 0; //if($quizId) { // if(!current_user_can('wpProQuiz_edit_quiz')) { // wp_die(__('You do not have sufficient permissions to access this page.')); // } //} else { // if(!current_user_can('wpProQuiz_add_quiz')) { // wp_die(__('You do not have sufficient permissions to access this page.')); // } //} $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); $quiz = new WpProQuiz_Model_Quiz(); $forms = null; $prerequisiteQuizList = array(); if(!empty($get["post_id"])) { $quiz_post = get_post($get["post_id"]); if ( ( !empty( $quiz_post ) ) && ( is_a( $quiz_post, 'WP_Post' ) ) ) { $this->_post["name"] = $quiz_post->post_title; } } if($quizId && $quizMapper->exists($quizId) == 0) { WpProQuiz_View_View::admin_notices( esc_html__( 'Missing ProQuiz Associated Settings.', 'learndash' ), 'error' ); $this->view = new WpProQuiz_View_QuizEdit(); $this->view->quiz = $quiz; $this->view->forms = $forms; $this->view->prerequisiteQuizList = $prerequisiteQuizList; $this->view->templates = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false); $this->view->quizList = $quizMapper->fetchAllAsArray(array('id', 'name'), $quizId ? array($quizId) : array()); $this->view->captchaIsInstalled = class_exists('ReallySimpleCaptcha'); return $this->view; } if ( ( isset( $get['templateLoad'] ) ) && ( ! empty( $get['templateLoad'] ) ) && ( isset( $get['templateLoadId'] ) ) && ( ! empty( $get['templateLoadId'] ) ) ) { $template = $templateMapper->fetchById( (int) $get['templateLoadId'] ); if ( ( $template ) && is_a( $template, 'WpProQuiz_Model_Template' ) ) { $data = $template->getData(); if ( $data !== null ) { $quiz = $data['quiz']; $quiz->setId( $quizId ); $quiz->setName($this->_post["name"]); $quiz->setText("AAZZAAZZ"); //$quizMapper->save( $quiz ); //if ( empty( $quizId ) && ! empty( $get["post_id"] ) ) { // learndash_update_setting($get["post_id"], "quiz_pro", $quiz->getId()); //} //$quizId = $quiz->getId(); $forms = $data['forms']; $prerequisiteQuizList = $data['prerequisiteQuizList']; } } } else { $quiz = $quizMapper->fetch($quizId); $forms = $formMapper->fetch($quizId); $prerequisiteQuizList = $prerequisiteMapper->fetchQuizIds($quizId); } $this->view = new WpProQuiz_View_QuizEdit(); $this->view->quiz = $quiz; $this->view->forms = $forms; $this->view->prerequisiteQuizList = $prerequisiteQuizList; $this->view->templates = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false); $this->view->quizList = $quizMapper->fetchAllAsArray(array('id', 'name'), $quizId ? array($quizId) : array()); $this->view->captchaIsInstalled = class_exists('ReallySimpleCaptcha'); $this->view->header = $quizId ? sprintf( esc_html_x('Edit %s', 'Edit quiz', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ) : sprintf( esc_html_x('Create %s', 'Create quiz', 'learndash'), learndash_get_custom_label_lower( 'quiz' )); return $this->view; } public function checkLock() { if($userId > 0) { $quizIds = $prerequisiteMapper->getNoPrerequisite($quizId, $userId); } else { $checkIds = $prerequisiteMapper->fetchQuizIds($quizId); if(isset($this->_post['wpProQuiz_result'])) { $r = json_encode($this->_post['wpProQuiz_result'], true); if($r !== null && is_array($r)) { foreach($checkIds as $id) { if(!isset($r[$id]) || !$r[$id]) { $quizIds[] = $id; } } } } else { $quizIds = $checkIds; } } $names = $quizMapper->fetchCol($quizIds, 'name'); } public function isLockQuiz($quizId) { $quizId = (int)$this->_post['quizId']; $userId = get_current_user_id(); $data = array(); if ( learndash_is_admin_user( $userId ) ) { $bypass_course_limits_admin_users = LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Section_General_Admin_User', 'bypass_course_limits_admin_users' ); if ( $bypass_course_limits_admin_users == 'yes' ) { return $data; } } $lockMapper = new WpProQuiz_Model_LockMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); $quiz = $quizMapper->fetch($this->_post['quizId']); if($quiz === null || $quiz->getId() <= 0) { return null; } if($this->isPreLockQuiz($quiz)) { $lockIp = $lockMapper->isLock($this->_post['quizId'], $this->getIp(), $userId, WpProQuiz_Model_Lock::TYPE_QUIZ); $lockCookie = false; $cookieTime = $quiz->getQuizRunOnceTime(); if(isset($this->_cookie['wpProQuiz_lock']) && $userId == 0 && $quiz->isQuizRunOnceCookie()) { $cookieJson = json_decode($this->_cookie['wpProQuiz_lock'], true); if($cookieJson !== false) { if(isset($cookieJson[$this->_post['quizId']]) && $cookieJson[$this->_post['quizId']] == $cookieTime) { $lockCookie = true; } } } $data['lock'] = array( 'is' => ($lockIp || $lockCookie), 'pre' => true ); } if($quiz->isPrerequisite()) { $quizIds = array(); if($userId > 0) { $quizIds = $prerequisiteMapper->getNoPrerequisite($quizId, $userId); } else { $checkIds = $prerequisiteMapper->fetchQuizIds($quizId); if(isset($this->_cookie['wpProQuiz_result'])) { $r = json_decode($this->_cookie['wpProQuiz_result'], true); if($r !== null && is_array($r)) { foreach($checkIds as $id) { if(!isset($r[$id]) || !$r[$id]) { $quizIds[] = $id; } } } } else { $quizIds = $checkIds; } } if(!empty($quizIds)) { $post_quiz_ids = array(); foreach( $quizIds as $pro_quiz_id ) { $post_quiz_id = learndash_get_quiz_id_by_pro_quiz_id( $pro_quiz_id ); if ( ! empty( $post_quiz_id ) ) { $post_quiz_ids[$post_quiz_id] = $pro_quiz_id; } } if ( !empty( $post_quiz_ids ) ) { if ( ( isset( $this->_post['course_id'] ) ) && ( ! empty( $this->_post['course_id'] ) ) ) { $post_course_id = intval( $this->_post['course_id'] ); } else { $post_course_id = 0; } $post_course_id = apply_filters( 'learndash_quiz_prerequisite_course_check', $post_course_id, $userId, $post_quiz_ids ); $post_quiz_ids = learndash_is_quiz_notcomplete($userId, $post_quiz_ids, true, -1 ); if ( !empty( $post_quiz_ids ) ) { $quizIds = array_values( $post_quiz_ids ); } else { $quizIds = array(); } } if (!empty($quizIds)) { $names = $quizMapper->fetchCol($quizIds, 'name'); if(!empty($names)) { $data['prerequisite'] = implode(', ', $names); } } } } if($quiz->isStartOnlyRegisteredUser()) { $data['startUserLock'] = (int)!is_user_logged_in(); } return $data; } public function loadQuizData() { $quizId = (int)$_POST['quizId']; $userId = get_current_user_id(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $toplistController = new WpProQuiz_Controller_Toplist(); $statisticController = new WpProQuiz_Controller_Statistics(); $quiz = $quizMapper->fetch($quizId); $data = array(); if($quiz === null || $quiz->getId() <= 0) { return array(); } $data['toplist'] = $toplistController->getAddToplist($quiz); if ( $quiz->isShowAverageResult() ) { $data['averageResult'] = $statisticController->getAverageResult($quizId); } else { $data['averageResult'] = 0; } /* $data['quiz_repeats'] = (int)0; $data['user_attempts_left'] = (int)0; $data['user_attempts_taken'] = (int)0; // We need the user quiz stats when they click the start quiz button $quiz_post_id = learndash_get_quiz_id_by_pro_quiz_id( $quizId ); if (!empty($quiz_post_id)) { $quiz_post_meta = get_post_meta( $quiz_post_id, '_sfwd-quiz', true); if ( isset( $quiz_post_meta['sfwd-quiz_repeats'] ) ) { $data['quiz_repeats'] = intval( $quiz_post_meta['sfwd-quiz_repeats'] ); } } if ( !empty( $userId ) ) { $usermeta = get_user_meta( $userId, '_sfwd-quizzes', true ); $usermeta = maybe_unserialize( $usermeta ); if ( ! is_array( $usermeta ) ) { $usermeta = array(); } if ( ! empty( $usermeta ) ) { foreach ( $usermeta as $k => $v ) { if ( $v['quiz'] == $quiz_post_id ) { //error_log('match quiz
'. print_r($v, true) .''); $data['user_attempts_taken'] += 1; } } } $data['user_attempts_left'] = (int)( $data['quiz_repeats'] == '' || $data['quiz_repeats'] >= $data['user_attempts_taken'] ); } */ return $data; } private function resetLock($quizId) { if(!current_user_can('wpProQuiz_edit_quiz')) { exit; } $lm = new WpProQuiz_Model_LockMapper(); $qm = new WpProQuiz_Model_QuizMapper(); $q = $qm->fetch($quizId); if($q->getId() > 0) { $q->setQuizRunOnceTime(time()); $qm->save($q); $lm->deleteByQuizId($quizId, WpProQuiz_Model_Lock::TYPE_QUIZ); } exit; } private function showAction() { if(!current_user_can('wpProQuiz_show')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $this->view = new WpProQuiz_View_QuizOverall(); $m = new WpProQuiz_Model_QuizMapper(); $this->view->quiz = $m->fetchAll(); $this->view->show(); } private function editAction($id) { if(!current_user_can('wpProQuiz_edit_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); $m = new WpProQuiz_Model_QuizMapper(); $this->view = new WpProQuiz_View_QuizEdit(); $this->view->header = sprintf( esc_html_x('Edit %s', 'Edit quiz', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ); $forms = $formMapper->fetch($id); $prerequisiteQuizList = $prerequisiteMapper->fetchQuizIds($id); if($m->exists($id) == 0) { WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s not found', 'Quiz not found', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ), 'error'); return; } if(isset($this->_post['submit'])) { if(isset($this->_post['resultGradeEnabled'])) { $this->_post['result_text'] = $this->filterResultTextGrade($this->_post); } $quiz = new WpProQuiz_Model_Quiz($this->_post); $quiz->setId($id); if($this->checkValidit($this->_post)) { //WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%s edited', 'Quiz edited', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' )), 'info'); $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); $prerequisiteMapper->delete($id); if($quiz->isPrerequisite() && !empty($this->_post['prerequisiteList'])) { $prerequisiteMapper->save($id, $this->_post['prerequisiteList']); $quizMapper->activateStatitic($this->_post['prerequisiteList'], 1440); } if(!$this->formHandler($quiz->getId(), $this->_post)) { $quiz->setFormActivated(false); } $quizMapper->save($quiz); $this->showAction(); return; } else { //WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%1$s title or %2$s description are not filled', 'Quiz title or quiz description are not filled', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ), learndash_get_custom_label_lower( 'quiz' )) ); } } else if(isset($this->_post['template']) || isset($this->_post['templateLoad'])) { if(isset($this->_post['template'])) $template = $this->saveTemplate(); else $template = $templateMapper->fetchById($this->_post['templateLoadId']); $data = $template->getData(); if($data !== null) { $quiz = $data['quiz']; $forms = $data['forms']; $prerequisiteQuizList = $data['prerequisiteQuizList']; } } else { $quiz = $m->fetch($id); } $this->view->quiz = $quiz; $this->view->prerequisiteQuizList = $prerequisiteQuizList; $this->view->quizList = $m->fetchAllAsArray(array('id', 'name'), array($id)); $this->view->captchaIsInstalled = class_exists('ReallySimpleCaptcha'); $this->view->forms = $forms; $this->view->templates = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false); $this->view->show(); } private function createAction() { if(!current_user_can('wpProQuiz_add_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $this->view = new WpProQuiz_View_QuizEdit(); $this->view->header = sprintf( esc_html_x('Create %s', 'Create quiz', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ); $forms = null; $prerequisiteQuizList = array(); $m = new WpProQuiz_Model_QuizMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); if(isset($this->_post['submit'])) { if(isset($this->_post['resultGradeEnabled'])) { $this->_post['result_text'] = $this->filterResultTextGrade($this->_post); } $quiz = new WpProQuiz_Model_Quiz($this->_post); $quizMapper = new WpProQuiz_Model_QuizMapper(); if($this->checkValidit($this->_post)) { //WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('Create %s', 'Create quiz', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ), 'info'); $quizMapper->save($quiz); $id = $quizMapper->getInsertId(); $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); if($quiz->isPrerequisite() && !empty($this->_post['prerequisiteList'])) { $prerequisiteMapper->save($id, $this->_post['prerequisiteList']); $quizMapper->activateStatitic($this->_post['prerequisiteList'], 1440); } if(!$this->formHandler($id, $this->_post)) { $quiz->setFormActivated(false); $quizMapper->save($quiz); } $this->showAction(); return; } else { //WpProQuiz_View_View::admin_notices( sprintf( esc_html_x('%1$s title or %2$s description are not filled', 'Quiz title or quiz description are not filled', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ), learndash_get_custom_label_lower( 'quiz' )) ); } } else if(isset($this->_post['template']) || isset($this->_post['templateLoad'])) { if(isset($this->_post['template'])) $template = $this->saveTemplate(); else $template = $templateMapper->fetchById($this->_post['templateLoadId']); $data = $template->getData(); if($data !== null) { $quiz = $data['quiz']; $forms = $data['forms']; $prerequisiteQuizList = $data['prerequisiteQuizList']; } } else { $quiz = new WpProQuiz_Model_Quiz(); } $this->view->quiz = $quiz; $this->view->prerequisiteQuizList = $prerequisiteQuizList; $this->view->quizList = $m->fetchAllAsArray(array('id', 'name')); $this->view->captchaIsInstalled = class_exists('ReallySimpleCaptcha'); $this->view->forms = $forms; $this->view->templates = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false); $this->view->show(); } private function saveTemplate() { $templateMapper = new WpProQuiz_Model_TemplateMapper(); if(isset($this->_post['resultGradeEnabled'])) { $this->_post['result_text'] = $this->filterResultTextGrade($this->_post); } $quiz = new WpProQuiz_Model_Quiz($this->_post); if($quiz->isPrerequisite() && !empty($this->_post['prerequisiteList']) && !$quiz->isStatisticsOn()) { $quiz->setStatisticsOn(true); $quiz->setStatisticsIpLock(1440); } $form = $this->_post['form']; unset($form[0]); $forms = array(); foreach($form as $f) { if ( isset( $f['fieldname'] ) ) { $f['fieldname'] = trim( $f['fieldname'] ); if ( empty( $f['fieldname'] ) ) { continue; } if ( absint( $f['form_id'] ) && absint( $f['form_delete'] ) ) { continue; } if( $f['type'] == WpProQuiz_Model_Form::FORM_TYPE_SELECT || $f['type'] == WpProQuiz_Model_Form::FORM_TYPE_RADIO ) { if(!empty($f['data'])) { $items = explode("\n", $f['data']); $f['data'] = array(); foreach ($items as $item) { $item = trim($item); if(!empty($item)) $f['data'][] = $item; } } } if(empty($f['data']) || !is_array($f['data'])) $f['data'] = null; $forms[] = new WpProQuiz_Model_Form($f); } } //WpProQuiz_View_View::admin_notices(__('Template stored', 'learndash'), 'info'); $data = array( 'quiz' => $quiz, 'forms' => $forms, 'prerequisiteQuizList' => isset($this->_post['prerequisiteList']) ? $this->_post['prerequisiteList'] : array() ); $quiz_post_id = $quiz->getPostId(); if ( ! empty( $quiz_post_id ) ) { $data['_' . learndash_get_post_type_slug( 'quiz' ) ] = learndash_get_setting( $quiz_post_id ); } // Zero out the ProQuiz Post ID and the reference for the associated settings. $data['quiz']->setPostId(0); $data['_' . learndash_get_post_type_slug( 'quiz' ) ]['quiz_pro'] = 0; $template = new WpProQuiz_Model_Template(); if($this->_post['templateSaveList'] == '0') { $template->setName(trim($this->_post['templateName'])); } else { $template = $templateMapper->fetchById($this->_post['templateSaveList'], false); } $template->setType(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ); $template->setData($data); $templateMapper->save($template); return $template; } private function formHandler($quizId, $post) { if(!isset($post['form'])) return false; $form = $post['form']; unset($form[0]); if(empty($form)) return false; $formMapper = new WpProQuiz_Model_FormMapper(); $deleteIds = array(); $forms = array(); $sort = 0; foreach($form as $f) { if ( ( !isset( $f['fieldname'] ) ) || ( empty( $f['fieldname'] ) ) ) continue; $f['fieldname'] = trim($f['fieldname']); if((int) $f['form_id'] && (int) $f['form_delete']) { $deleteIds[] = (int) $f['form_id']; continue; } $f['sort'] = $sort++; $f['quizId'] = $quizId; if($f['type'] == WpProQuiz_Model_Form::FORM_TYPE_SELECT || $f['type'] == WpProQuiz_Model_Form::FORM_TYPE_RADIO) { if(!empty($f['data'])) { $items = explode("\n", $f['data']); $f['data'] = array(); foreach ($items as $item) { $item = trim($item); if(!empty($item)) $f['data'][] = $item; } } } if(empty($f['data']) || !is_array($f['data'])) $f['data'] = null; $forms[] = new WpProQuiz_Model_Form($f); } if(!empty($deleteIds)) $formMapper->deleteForm($deleteIds, $quizId); $formMapper->update($forms); return !empty($forms); } private function deleteAction($id) { if(!current_user_can('wpProQuiz_delete_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $m = new WpProQuiz_Model_QuizMapper(); // $qm = new WpProQuiz_Model_QuestionMapper(); // $lm = new WpProQuiz_Model_LockMapper(); // $srm = new WpProQuiz_Model_StatisticRefMapper(); // $pm = new WpProQuiz_Model_PrerequisiteMapper(); // $tm = new WpProQuiz_Model_ToplistMapper(); // $m->delete($id); // $qm->deleteByQuizId($id); // $lm->deleteByQuizId($id); // $srm->deleteAll($id); // $pm->delete($id); // $tm->delete($id); $m->deleteAll($id); //WpProQuiz_View_View::admin_notices(sprintf( esc_html_x('%s deleted', 'Quiz deleted', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ), 'info'); $this->showAction(); } private function checkValidit($post) { if ( ( isset( $post['name'] ) ) && ( ! empty( $post['name'] ) ) && ( isset( $post['text'] ) ) && ( ! empty( $post['text'] ) ) ) { return true; } if ( ( isset( $post['post_ID'] ) ) && ( ! empty( $post['post_ID'] ) ) ) { if ( learndash_get_post_type_slug( 'quiz' ) === get_post_type( absint( $post['post_ID'] ) ) ) { return true; } } } private function filterResultTextGrade($post) { $result = array(); $sorted = array(); if ( isset( $post['resultTextGrade'] ) ) { $sorted = learndash_quiz_result_message_sort( $post['resultTextGrade'] ); return $sorted; } // if ( ! empty( $sorted ) ) { // foreach ( $sorted as $item ) { // $result['text'][] = $item['text']; // $result['prozent'][] = $item['prozent']; // } // } return $result; } private function setResultCookie(WpProQuiz_Model_Quiz $quiz) { $prerequisite = new WpProQuiz_Model_PrerequisiteMapper(); if(get_current_user_id() == 0 && $prerequisite->isQuizId($quiz->getId())) { $cookieData = array(); if(isset($this->_cookie['wpProQuiz_result'])) { $d = json_decode($this->_cookie['wpProQuiz_result'], true); if($d !== null && is_array($d)) { $cookieData = $d; } } $cookieData[$quiz->getId()] = 1; $url = parse_url(get_bloginfo( 'url' )); setcookie('wpProQuiz_result', json_encode($cookieData), time() + 60*60*24*300, empty($url['path']) ? '/' : $url['path']); } } public function completedQuiz() { $lockMapper = new WpProQuiz_Model_LockMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $is100P = $this->_post['results']['comp']['result'] == 100; $userId = get_current_user_id(); $quiz = $quizMapper->fetch($this->_post['quizId']); if ( ( isset( $this->_post['quiz'] ) ) && ( ! empty( $this->_post['quiz'] ) ) ) { if ( absint( $this->_post['quiz'] ) !== absint( $quiz->getPostId() ) ) { $quiz->setPostId( absint( $this->_post['quiz'] ) ); } } if ( $quiz === null || $quiz->getId() <= 0 ) { exit; } $categories = $categoryMapper->fetchByQuiz($quiz); $this->setResultCookie( $quiz ); $this->emailNote( $quiz, $this->_post['results']['comp'], $categories ); if( ! $this->isPreLockQuiz( $quiz ) ) { $statistics = new WpProQuiz_Controller_Statistics(); $statisticRefMapper_id = $statistics->save($quiz); do_action('wp_pro_quiz_completed_quiz', $statisticRefMapper_id) ; if ( $is100P ) do_action( 'wp_pro_quiz_completed_quiz_100_percent' ); exit; } $lockMapper->deleteOldLock(60*60*24*7, $this->_post['quizId'], time(), WpProQuiz_Model_Lock::TYPE_QUIZ, 0); $lockIp = $lockMapper->isLock($this->_post['quizId'], $this->getIp(), get_current_user_id(), WpProQuiz_Model_Lock::TYPE_QUIZ); $lockCookie = false; $cookieTime = $quiz->getQuizRunOnceTime(); $cookieJson = null; if(isset($this->_cookie['wpProQuiz_lock']) && get_current_user_id() == 0 && $quiz->isQuizRunOnceCookie()) { $cookieJson = json_decode($this->_cookie['wpProQuiz_lock'], true); if($cookieJson !== false) { if(isset($cookieJson[$this->_post['quizId']]) && $cookieJson[$this->_post['quizId']] == $cookieTime) { $lockCookie = true; } } } if(!$lockIp && !$lockCookie) { $statistics = new WpProQuiz_Controller_Statistics(); $statisticRefMapper_id = $statistics->save($quiz); //do_action('wp_pro_quiz_completed_quiz'); do_action('wp_pro_quiz_completed_quiz', $statisticRefMapper_id); if($is100P) do_action('wp_pro_quiz_completed_quiz_100_percent'); if(get_current_user_id() == 0 && $quiz->isQuizRunOnceCookie()) { $cookieData = array(); if($cookieJson !== null || $cookieJson !== false) { $cookieData = $cookieJson; } $cookieData[$this->_post['quizId']] = $quiz->getQuizRunOnceTime(); $url = parse_url(get_bloginfo( 'url' )); setcookie('wpProQuiz_lock', json_encode($cookieData), time() + 60*60*24*60, empty($url['path']) ? '/' : $url['path']); } $lock = new WpProQuiz_Model_Lock(); $lock->setUserId(get_current_user_id()); $lock->setQuizId($this->_post['quizId']); $lock->setLockDate(time()); $lock->setLockIp($this->getIp()); $lock->setLockType(WpProQuiz_Model_Lock::TYPE_QUIZ); $lockMapper->insert($lock); } exit; } public function isPreLockQuiz(WpProQuiz_Model_Quiz $quiz) { $userId = get_current_user_id(); if($quiz->isQuizRunOnce()) { switch ($quiz->getQuizRunOnceType()) { case WpProQuiz_Model_Quiz::QUIZ_RUN_ONCE_TYPE_ALL: return true; case WpProQuiz_Model_Quiz::QUIZ_RUN_ONCE_TYPE_ONLY_USER: return $userId > 0; case WpProQuiz_Model_Quiz::QUIZ_RUN_ONCE_TYPE_ONLY_ANONYM: return $userId == 0; } } return false; } private function getIp() { if(get_current_user_id() > 0) return '0'; else return filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); } private function emailNote(WpProQuiz_Model_Quiz $quiz, $result, $categories) { $globalMapper = new WpProQuiz_Model_GlobalSettingsMapper(); $email_settings_admin = LearnDash_Settings_Section::get_section_settings_all( 'LearnDash_Settings_Quizzes_Admin_Email' ); //error_log('email_settings_admin
'. print_r($email_settings_admin, true) .''); $email_settings_user = LearnDash_Settings_Section::get_section_settings_all( 'LearnDash_Settings_Quizzes_User_Email' ); //error_log('email_settings_user
'. print_r($email_settings_user, true) .''); $user = wp_get_current_user(); $r = array( '$userId' => $user->ID, '$username' => $user->display_name, '$quizname' => $quiz->getName(), '$result' => $result['result'].'%', '$points' => $result['points'], '$ip' => filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP), '$categories' => empty($result['cats']) ? '' : $this->setCategoryOverview($result['cats'], $categories) ); if($user->ID == 0) { $r['$username'] = $r['$ip']; } if($quiz->isUserEmailNotification()) { //$msg = str_replace(array_keys($r), $r, $userEmail['message']); $msg = str_replace(array_keys($r), $r, $email_settings_user['user_mail_message']); $msg = apply_filters( 'learndash_quiz_email_note_user_message', $msg, $r, $quiz, $result, $categories ); $headers = ''; if ( ( isset( $email_settings_user['user_mail_from'] ) ) && ( !empty( $email_settings_user['user_mail_from'] ) ) && ( is_email( $email_settings_user['user_mail_from'] ) ) ) { if ( ( !isset( $email_settings_user['user_mail_from_name'] ) ) || ( empty( $email_settings_user['user_mail_from_name'] ) ) ) { $email_settings_user['user_mail_from_name'] = ''; $email_user = get_user_by('emal', $email_settings_user['user_mail_from'] ); if ( ( $email_user ) && ( is_a( $email_user, 'WP_User' ) ) ) { $email_settings_user['user_mail_from_name'] = $email_user->display_name; } } $headers .= 'From: '; if ( ( isset( $email_settings_user['user_mail_from_name'] ) ) && ( !empty( $email_settings_user['user_mail_from_name'] ) ) ) { $headers .= $email_settings_user['user_mail_from_name'] .' <'. $email_settings_user['user_mail_from'] .'>'; } else { $headers .= $email_settings_user['user_mail_from']; } } if ( ( isset( $email_settings_user['user_mail_html'] ) ) && ( 'yes' === $email_settings_user['user_mail_html'] ) ) { add_filter( 'wp_mail_content_type', array( $this, 'htmlEmailContent' ) ); $msg = wpautop( $msg ); } $email_params = array( "email" => $user->user_email, "subject" => $email_settings_user['user_mail_subject'], "msg" => $msg, "headers" => $headers ); $email_params = apply_filters("learndash_quiz_email", $email_params, $quiz); //error_log('Quiz User Email params
'. print_r($email_params, true) .''); wp_mail( $email_params['email'], $email_params['subject'], $email_params['msg'], $email_params['headers'] ); if ( ( isset( $email_settings_user['user_mail_html'] ) ) && ( 'yes' === $email_settings_user['user_mail_html'] ) ) { remove_filter( 'wp_mail_content_type', array( $this, 'htmlEmailContent' ) ); } } if($quiz->getEmailNotification() == WpProQuiz_Model_Quiz::QUIZ_EMAIL_NOTE_ALL || (get_current_user_id() > 0 && $quiz->getEmailNotification() == WpProQuiz_Model_Quiz::QUIZ_EMAIL_NOTE_REG_USER)) { $msg = str_replace( array_keys( $r ), $r, $email_settings_admin['admin_mail_message'] ); $msg = apply_filters( 'learndash_quiz_email_note_admin_message', $msg, $r, $quiz, $result, $categories ); $headers = ''; if ( ( ! isset( $email_settings_admin['admin_mail_from'] ) ) || ( empty( $email_settings_admin['admin_mail_from'] ) ) || ( !is_email( $email_settings_admin['admin_mail_from'] ) ) ) { $email_settings_admin['admin_mail_from'] = get_option( 'admin_email' ); } if ( ( !isset( $email_settings_admin['admin_mail_from_name'] ) ) || ( empty( $email_settings_admin['admin_mail_from_name'] ) ) ) { $email_settings_admin['admin_mail_from_name'] = ''; if ( ! empty( $email_settings_admin['admin_mail_from'] ) ) { $email_user = get_user_by('emal', $email_settings_admin['admin_mail_from'] ); if ( ( $email_user ) && ( is_a( $email_user, 'WP_User' ) ) ) { $email_settings_admin['admin_mail_from_name'] = $email_user->display_name; } } } if ( ! empty( $email_settings_admin['admin_mail_from'] ) ) { $headers .= 'From: '; if ( ( isset( $email_settings_admin['admin_mail_from_name'] ) ) && ( !empty( $email_settings_admin['admin_mail_from_name'] ) ) ) { $headers .= $email_settings_admin['admin_mail_from_name'] .' <'. $email_settings_admin['admin_mail_from'] .'>'; } else { $headers .= $email_settings_admin['admin_mail_from']; } } if ( ( isset( $email_settings_admin['admin_mail_html'] ) ) && ( $email_settings_admin['admin_mail_html'] ) ) { add_filter( 'wp_mail_content_type', array( $this, 'htmlEmailContent' ) ); $msg = wpautop( $msg ); } $email_params = array( 'email' => $email_settings_admin['admin_mail_to'], 'subject' => $email_settings_admin['admin_mail_subject'], 'msg' => $msg, 'headers' => $headers ); $email_params = apply_filters( 'learndash_quiz_email_admin', $email_params, $quiz); //error_log('Quiz Admin Email params
'. print_r($email_params, true) .''); wp_mail($email_params['email'], $email_params['subject'], $email_params['msg'], $email_params['headers'] ); if ( ( isset( $email_settings_admin['admin_mail_html'] ) ) && ( 'yes' === $email_settings_admin['admin_mail_html'] ) ) { remove_filter( 'wp_mail_content_type', array( $this, 'htmlEmailContent' ) ); } } } public function htmlEmailContent($contentType) { return 'text/html'; } private function setCategoryOverview( $category_scores = array() , $question_cats = array() ) { if ( ( ! empty( $category_scores ) ) && ( ! empty( $question_cats ) ) ) { $question_categories = array(); foreach ( $question_cats as $cat ) { if ( ! $cat->getCategoryId() ) { $cat->setCategoryName( esc_html__( 'Not categorized', 'learndash' ) ); } $question_categories[ $cat->getCategoryId() ] = $cat->getCategoryName(); } } $output = SFWD_LMS::get_template( 'quiz_result_categories_email.php', array( 'question_categories' => $question_categories, 'category_scores' => $category_scores, ) ); return $output; //$cats = array(); // //foreach($categories as $cat) { // /* @var $cat WpProQuiz_Model_Category */ // // if(!$cat->getCategoryId()) { // $cat->setCategoryName(__('Not categorized', 'learndash')); // } // // $cats[$cat->getCategoryId()] = $cat->getCategoryName(); //} // //$a = esc_html__('Categories', 'learndash').":\n"; // //foreach($catArray as $id => $value) { // if(!isset($cats[$id])) // continue; // // $a .= '* '.str_pad($cats[$id], 35, '.').((float)$value)."%\n"; //} // //return $a; } } lib/controller/WpProQuiz_Controller_Request.php 0000666 00000001311 15214236625 0016047 0 ustar 00 handleExport(); } else { $this->handleImport(); } } private function handleExport() { if(!current_user_can('wpProQuiz_export')) { wp_die(__('You do not have sufficient permissions to access this page.')); } if(isset($this->_post ['exportType']) && $this->_post ['exportType'] == 'xml') { $export = new WpProQuiz_Helper_ExportXml(); $filename = 'WpProQuiz_export_'.time().'.xml'; } else { $export = new WpProQuiz_Helper_Export(); $filename = 'WpProQuiz_export_'.time().'.wpq'; } $a = $export->export($this->_post['exportIds']); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.$filename.'"'); echo $a; exit; } private function handleImport() { if(!current_user_can('wpProQuiz_import')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $this->view = new WpProQuiz_View_Import(); $this->view->error = false; if(isset($_FILES, $_FILES['import']) && substr($_FILES['import']['name'], -3) == 'xml' || isset($this->_post['importType']) && $this->_post['importType'] == 'xml') { $import = new WpProQuiz_Helper_ImportXml(); $importType = 'xml'; } else { $import = new WpProQuiz_Helper_Import(); $importType = 'wpq'; } $this->view->importType = $importType; if(isset($_FILES, $_FILES['import']) && $_FILES['import']['error'] == 0) { if($import->setImportFileUpload($_FILES['import']) === false) { $this->view->error = $import->getError(); } else { $data = $import->getImportData(); if($data === false) { $this->view->error = $import->getError(); } $this->view->import = $data; $this->view->importData = $import->getContent(); unset($data); } } else if(isset($this->_post, $this->_post['importSave'])) { if($import->setImportString($this->_post['importData']) === false) { $this->view->error = $import->getError(); } else { $ids = isset($this->_post['importItems']) ? $this->_post['importItems'] : false; if($ids !== false && $import->saveImport($ids) === false) { $this->view->error = $import->getError(); } else { $this->view->finish = true; $this->view->import_post_id = absint( $import->import_post_id ); } } } else { $this->view->error = esc_html__('File cannot be processed', 'learndash'); } $this->view->show(); } } lib/controller/WpProQuiz_Controller_Question.php 0000666 00000041415 15214236625 0016237 0 ustar 00 _quizId = (int) $_GET['quiz_id']; $action = isset( $_GET['action'] ) ? $_GET['action'] : 'show'; $m = new WpProQuiz_Model_QuizMapper(); if ( $m->exists( $this->_quizId ) == 0 ) { WpProQuiz_View_View::admin_notices( sprintf( esc_html_x( '%s not found', 'Quiz not found', 'learndash' ), LearnDash_Custom_Label::get_label( 'quiz' ) ),'error' ); return; } // if(isset($this->_post['hidden_action'])) { // switch ($this->_post['hidden_action']) { // case 'edit': // $this->editPostAction($this->_post['questionId']); // break; // } // } switch ( $action ) { // case 'add': // $this->createAction(); // break; case 'show': $this->showAction(); break; case 'addEdit': $this->addEditQuestion( (int) $_GET['quiz_id'] ); break; // case 'edit': // $this->editAction($_GET['id']); // break; case 'delete': $this->deleteAction( $_GET['id'] ); break; case 'save_sort': $this->saveSort(); break; case 'load_question': $this->loadQuestion( $_GET['quiz_id'] ); break; case 'copy_question': $this->copyQuestion( $_GET['quiz_id'] ); break; } } private function addEditQuestion( $quizId ) { $questionId = isset( $_GET['questionId'] ) ? (int) $_GET['questionId'] : 0; if ( $questionId ) { if ( ! current_user_can( 'wpProQuiz_edit_quiz' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'learndash' ) ); } } else { if ( ! current_user_can( 'wpProQuiz_add_quiz' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'learndash' ) ); } } $quizMapper = new WpProQuiz_Model_QuizMapper(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $cateoryMapper = new WpProQuiz_Model_CategoryMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); if ( $questionId && $questionMapper->existsAndWritable( $questionId ) == 0 ) { WpProQuiz_View_View::admin_notices( esc_html__( 'Question not found', 'learndash' ), 'error' ); return; } $question = new WpProQuiz_Model_Question(); if ( isset( $this->_post['template'] ) || ( isset( $this->_post['templateLoad'] ) && isset( $this->_post['templateLoadId'] ) ) ) { if ( isset( $this->_post['template'] ) ) { $template = $this->saveTemplate(); } else { $template = $templateMapper->fetchById( $this->_post['templateLoadId'] ); } $data = $template->getData(); if ( $data !== null ) { $question = $data['question']; $question->setId( $questionId ); $question->setQuizId( $quizId ); } } else if ( isset( $this->_post['submit'] ) ) { $add_new_question_url = admin_url( "admin.php?page=ldAdvQuiz&module=question&action=addEdit&quiz_id=" . $quizId . "&post_id=" . @$_REQUEST["post_id"] ); $add_new_question = "" . esc_html__( "Click here to add another question.", 'learndash' ) . ""; //if ( $questionId ) { // WpProQuiz_View_View::admin_notices( esc_html__( 'Question edited', 'learndash' ) . ". " . $add_new_question, 'info' ); //} else { // WpProQuiz_View_View::admin_notices( esc_html__( 'Question added', 'learndash' ) . ". " . $add_new_question, 'info' ); //} $question = $questionMapper->save( $this->getPostQuestionModel( $quizId, $questionId ), true ); $questionId = $question->getId(); } else { if ( $questionId ) { $question = $questionMapper->fetch( $questionId ); } } $this->view = new WpProQuiz_View_QuestionEdit(); $this->view->categories = $cateoryMapper->fetchAll(); $this->view->quiz = $quizMapper->fetch( $quizId ); $this->view->templates = $templateMapper->fetchAll( WpProQuiz_Model_Template::TEMPLATE_TYPE_QUESTION, false ); $this->view->question = $question; $this->view->data = $this->setAnswerObject( $question ); $this->view->header = $questionId ? esc_html__( 'Edit question', 'learndash' ) : esc_html__( 'New question', 'learndash' ); if ( $this->view->question->isAnswerPointsActivated() ) { $this->view->question->setPoints( 1 ); } $this->view->show(); } private function saveTemplate() { $questionModel = $this->getPostQuestionModel( 0, 0 ); $templateMapper = new WpProQuiz_Model_TemplateMapper(); $template = new WpProQuiz_Model_Template(); if ( $this->_post['templateSaveList'] == '0' ) { $template->setName( trim( $this->_post['templateName'] ) ); } else { $template = $templateMapper->fetchById( $this->_post['templateSaveList'], false ); } $template->setType( WpProQuiz_Model_Template::TEMPLATE_TYPE_QUESTION ); $template->setData( array( 'question' => $questionModel ) ); return $templateMapper->save( $template ); } public function getPostQuestionModel( $quizId, $questionId ) { $questionMapper = new WpProQuiz_Model_QuestionMapper(); $post = WpProQuiz_Controller_Request::getPost(); $post['id'] = $questionId; $post['quizId'] = $quizId; $post['title'] = isset( $post['title'] ) ? trim( $post['title'] ) : ''; $post['sort'] = $questionMapper->getSort($questionId); $clearPost = $this->clearPost( $post ); $post['answerData'] = $clearPost['answerData']; if ( ( isset( $post['title'] ) ) && ( empty( $post['title'] ) ) ) { $count = $questionMapper->count( $quizId ); $post['title'] = sprintf( esc_html_x( 'Question: %d', 'placeholder: question count' , 'learndash' ), $count + 1 ); } if ( ( isset( $post['answerType'] ) ) && ( $post['answerType'] === 'assessment_answer' ) ) { $post['answerPointsActivated'] = 1; } if ( ( isset( $post['answerType'] ) ) && ( $post['answerType'] === 'essay' ) ) { $post['answerPointsActivated'] = 0; } if ( isset( $post['answerPointsActivated'] ) ) { if ( isset( $post['answerPointsDiffModusActivated'] ) ) { $post['points'] = $clearPost['maxPoints']; } else { $post['points'] = $clearPost['points']; } } if ( isset( $post['category'] ) ) { $post['categoryId'] = $post['category'] > 0 ? $post['category'] : 0; } else { $post['categoryId'] = 0; } return new WpProQuiz_Model_Question( $post ); } public function copyQuestion( $quizId ) { if ( ! current_user_can( 'wpProQuiz_edit_quiz' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'learndash' ) ); } $m = new WpProQuiz_Model_QuestionMapper(); $questions = $m->fetchById( $this->_post['copyIds'] ); foreach ( $questions as $question ) { $question->setId( 0 ); $question->setQuizId( $quizId ); $m->save( $question ); } //WpProQuiz_View_View::admin_notices( esc_html__( 'questions copied', 'learndash' ), 'info' ); $this->showAction(); } public function loadQuestion( $quizId ) { if ( ! current_user_can( 'wpProQuiz_edit_quiz' ) ) { echo json_encode( array() ); exit; } $quizMapper = new WpProQuiz_Model_QuizMapper(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $data = array(); $quiz = $quizMapper->fetchAll(); foreach ( $quiz as $qz ) { if ( $qz->getId() == $quizId ) { continue; } $question = $questionMapper->fetchAll( $qz->getId() ); $questionArray = array(); foreach ( $question as $qu ) { $questionArray[] = array( 'name' => $qu->getTitle(), 'id' => $qu->getId() ); } $data[] = array( 'name' => $qz->getName(), 'id' => $qz->getId(), 'question' => $questionArray ); } echo json_encode( $data ); exit; } public function saveSort() { if ( ! current_user_can( 'wpProQuiz_edit_quiz' ) ) { exit; } $mapper = new WpProQuiz_Model_QuestionMapper(); $map = $this->_post['sort']; foreach ( $map as $k => $v ) { $mapper->updateSort( $v, $k ); } exit; } public function deleteAction( $id ) { if ( ! current_user_can( 'wpProQuiz_delete_quiz' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'learndash' ) ); } $mapper = new WpProQuiz_Model_QuestionMapper(); $mapper->setOnlineOff( $id ); $this->showAction(); } /** * @deprecated */ public function editAction( $id ) { if ( ! current_user_can( 'wpProQuiz_edit_quiz' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'learndash' ) ); } $questionMapper = new WpProQuiz_Model_QuestionMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $cateoryMapper = new WpProQuiz_Model_CategoryMapper(); $this->view = new WpProQuiz_View_QuestionEdit(); $this->view->quiz = $quizMapper->fetch( $id ); $this->view->question = $questionMapper->fetch( $id ); $this->view->data = $this->setAnswerObject( $this->view->question ); $this->view->categories = $cateoryMapper->fetchAll(); $this->view->header = esc_html__( 'Edit question', 'learndash' ); if ( $this->view->question->isAnswerPointsActivated() ) { $this->view->question->setPoints( 1 ); } $this->view->show(); } /** * @deprecated */ public function editPostAction( $id ) { $mapper = new WpProQuiz_Model_QuestionMapper(); if ( isset( $this->_post['submit'] ) && $mapper->existsAndWritable( $id ) ) { $post = $this->_post; $post['id'] = $id; $post['title'] = isset( $post['title'] ) ? trim( $post['title'] ) : ''; $clearPost = $this->clearPost( $post ); $post['answerData'] = $clearPost['answerData']; if ( empty( $post['title'] ) ) { $question = $mapper->fetch( $id ); $post['title'] = sprintf( esc_html__( 'Question: %d', 'learndash' ), $question->getSort() + 1 ); } if ( $post['answerType'] === 'assessment_answer' ) { $post['answerPointsActivated'] = 1; } if ( $post['answerType'] === 'essay' ) { $post['answerPointsActivated'] = 0; } if ( isset( $post['answerPointsActivated'] ) ) { if ( isset( $post['answerPointsDiffModusActivated'] ) ) { $post['points'] = $clearPost['maxPoints']; } else { $post['points'] = $clearPost['points']; } } $post['categoryId'] = $post['category'] > 0 ? $post['category'] : 0; $mapper->save( new WpProQuiz_Model_Question( $post ), true ); //WpProQuiz_View_View::admin_notices( esc_html__( 'Question edited', 'learndash' ), 'info' ); } } /** * @deprecated */ public function createAction() { if ( ! current_user_can( 'wpProQuiz_add_quiz' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'learndash' ) ); } $quizMapper = new WpProQuiz_Model_QuizMapper(); $cateoryMapper = new WpProQuiz_Model_CategoryMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); $this->view = new WpProQuiz_View_QuestionEdit(); $this->view->question = new WpProQuiz_Model_Question(); $this->view->categories = $cateoryMapper->fetchAll(); $this->view->quiz = $quizMapper->fetch( $this->_quizId ); $this->view->data = $this->setAnswerObject(); $this->view->templates = $templateMapper->fetchAll( WpProQuiz_Model_Template::TEMPLATE_TYPE_QUESTION, false ); $this->view->header = esc_html__( 'New question', 'learndash' ); if ( $this->view->question->isAnswerPointsActivated() ) { $this->view->question->setPoints( 1 ); } $this->view->show(); } public function setAnswerObject( WpProQuiz_Model_Question $question = null ) { //Defaults $data = array( 'sort_answer' => array( new WpProQuiz_Model_AnswerTypes() ), 'classic_answer' => array( new WpProQuiz_Model_AnswerTypes() ), 'matrix_sort_answer' => array( new WpProQuiz_Model_AnswerTypes() ), 'cloze_answer' => array( new WpProQuiz_Model_AnswerTypes() ), 'free_answer' => array( new WpProQuiz_Model_AnswerTypes() ), 'assessment_answer' => array( new WpProQuiz_Model_AnswerTypes() ), 'essay' => array( new WpProQuiz_Model_AnswerTypes() ), ); if ( $question !== null ) { $type = $question->getAnswerType(); $type = ( $type == 'single' || $type == 'multiple' ) ? 'classic_answer' : $type; $answerData = $question->getAnswerData(); if ( ( isset( $data[ $type ] ) ) && ( $answerData !== null ) && ( !empty( $answerData ) ) ) { $data[ $type ] = $question->getAnswerData(); } } return $data; } public function clearPost( $post ) { if ( ( isset( $post['answerType'] ) ) && ( $post['answerType'] == 'cloze_answer' ) && ( isset( $post['answerData']['cloze'] ) ) ) { preg_match_all( '#\{(.*?)(?:\|(\d+))?(?:[\s]+)?\}#im', $post['answerData']['cloze']['answer'], $matches ); $points = 0; $maxPoints = 0; foreach ( $matches[2] as $match ) { if ( empty( $match ) ) { $match = 1; } $points += $match; $maxPoints = max( $maxPoints, $match ); } return array( 'points' => $points, 'maxPoints' => $maxPoints, 'answerData' => array( new WpProQuiz_Model_AnswerTypes( $post['answerData']['cloze'] ) ) ); } if ( ( isset( $post['answerType'] ) ) && ( $post['answerType'] == 'assessment_answer' ) && ( isset( $post['answerData']['assessment'] ) ) ) { preg_match_all( '#\{(.*?)\}#im', $post['answerData']['assessment']['answer'], $matches ); $points = 0; $maxPoints = 0; foreach ( $matches[1] as $match ) { preg_match_all( '#\[([^\|\]]+)(?:\|(\d+))?\]#im', $match, $ms ); $points += count( $ms[1] ); $maxPoints = max( $maxPoints, count( $ms[1] ) ); } return array( 'points' => $points, 'maxPoints' => $maxPoints, 'answerData' => array( new WpProQuiz_Model_AnswerTypes( $post['answerData']['assessment'] ) ) ); } if ( ( isset( $post['answerType'] ) ) && ( $post['answerType'] == 'essay' ) && ( isset( $post['answerData']['essay'] ) ) ) { $answerType = new WpProQuiz_Model_AnswerTypes( $post['answerData']['essay'] ); $answerType->setPoints( $post['points'] ); $answerType->setGraded( true ); $answerType->setGradedType( $post['answerData']['essay']['type'] ); $answerType->setGradingProgression( $post['answerData']['essay']['progression'] ); $points = $post['points']; return array( 'points' => $points, 'maxPoints' => $points, 'answerData' => array( $answerType ) ); } if ( isset( $post['answerData']['cloze'] ) ) { unset( $post['answerData']['cloze'] ); } if ( isset( $post['answerData']['assessment'] ) ) { unset( $post['answerData']['assessment'] ); } if ( isset( $post['answerData']['none'] ) ) { unset( $post['answerData']['none'] ); } $answerData = array(); $points = 0; $maxPoints = 0; if ( isset( $post['answerData'] ) ) { foreach ( $post['answerData'] as $k => $v ) { if ( ( isset( $v['answer'] ) ) && ( trim( $v['answer'] ) == '' ) ) { if ( $post['answerType'] != 'matrix_sort_answer' ) { continue; } else { if ( ( !isset( $v['sort_string'] ) ) || ( trim( $v['sort_string'] ) == '' ) ) { continue; } } } $answerType = new WpProQuiz_Model_AnswerTypes( $v ); if ( ( $post['answerType'] == 'matrix_sort_answer' ) || ( $post['answerType'] == 'sort_answer' ) ) { $points += $answerType->getPoints(); $maxPoints = max( $maxPoints, $answerType->getPoints() ); } else if ( $answerType->isCorrect() ) { $points += $answerType->getPoints(); $maxPoints = max( $maxPoints, $answerType->getPoints() ); } $answerData[] = $answerType; } } return array( 'points' => $points, 'maxPoints' => $maxPoints, 'answerData' => $answerData ); } public function clear( $a ) { foreach ( $a as $k => $v ) { if ( is_array( $v ) ) { $a[ $k ] = $this->clear( $a[ $k ] ); } if ( is_string( $a[ $k ] ) ) { $a[ $k ] = trim( $a[ $k ] ); if ( $a[ $k ] != '' ) { continue; } } if ( empty( $a[ $k ] ) ) { unset( $a[ $k ] ); } } return $a; } public function showAction() { if ( ! current_user_can( 'wpProQuiz_show' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'learndash' ) ); } $m = new WpProQuiz_Model_QuizMapper(); $mm = new WpProQuiz_Model_QuestionMapper(); $this->view = new WpProQuiz_View_QuestionOverall(); $this->view->quiz = $m->fetch( $this->_quizId ); //if ( isset( $_GET['post_id'] ) ) { // $quiz_post_id = absint( $_GET['post_id'] ); // if ( $quiz_post_id !== absint( $this->view->quiz->getPostId() ) ) { // $this->view->quiz->setPostId( $quiz_post_id ); // } //} //$this->view->question = $mm->fetchAll( $this->view->quiz ); $this->view->question = $mm->fetchAll( $this->_quizId ); $this->view->show(); } } lib/controller/WpProQuiz_Controller_GlobalSettings.php 0000666 00000004536 15214236625 0017354 0 ustar 00 edit(); } private function edit() { if(!current_user_can('wpProQuiz_change_settings')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $mapper = new WpProQuiz_Model_GlobalSettingsMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); $view = new WpProQuiz_View_GobalSettings(); if(isset($this->_post['submit'])) { $mapper->save(new WpProQuiz_Model_GlobalSettings($this->_post)); //WpProQuiz_View_View::admin_notices(__('Settings saved', 'learndash'), 'info'); $toplistDateFormat = $this->_post['toplist_date_format']; if($toplistDateFormat == 'custom') { $toplistDateFormat = trim($this->_post['toplist_date_format_custom']); } $statisticTimeFormat = $this->_post['statisticTimeFormat']; if(add_option('wpProQuiz_toplistDataFormat', $toplistDateFormat) === false) { update_option('wpProQuiz_toplistDataFormat', $toplistDateFormat); } if(add_option('wpProQuiz_statisticTimeFormat', $statisticTimeFormat, '', 'no') === false) { update_option('wpProQuiz_statisticTimeFormat', $statisticTimeFormat); } //Email $mapper->saveEmailSettiongs($this->_post['email']); $mapper->saveUserEmailSettiongs($this->_post['userEmail']); } else if(isset($this->_post['databaseFix'])) { //WpProQuiz_View_View::admin_notices(__('Database repaired', 'learndash'), 'info'); $DbUpgradeHelper = new WpProQuiz_Helper_DbUpgrade(); $DbUpgradeHelper->databaseDelta(); } $view->settings = $mapper->fetchAll(); $view->isRaw = !preg_match('[raw]', apply_filters('the_content', '[raw]a[/raw]')); $view->category = $categoryMapper->fetchAll(); $view->email = $mapper->getEmailSettings(); $view->userEmail = $mapper->getUserEmailSettings(); $view->templateQuiz = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false); $view->templateQuestion = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUESTION, false); $view->toplistDataFormat = get_option('wpProQuiz_toplistDataFormat', 'Y/m/d g:i A'); $view->statisticTimeFormat = get_option('wpProQuiz_statisticTimeFormat', 'Y/m/d g:i A'); $view->show(); } } lib/controller/WpProQuiz_Controller_StyleManager.php 0000666 00000002020 15214236625 0017010 0 ustar 00 show(); } private function show() { global $learndash_assets_loaded; //wp_enqueue_style( // 'wpProQuiz_front_style', // plugins_url('css/wpProQuiz_front'. leardash_min_asset() .'.css', WPPROQUIZ_FILE), // array(), // LEARNDASH_SCRIPT_VERSION_TOKEN //); //wp_style_add_data( 'wpProQuiz_front_style', 'rtl', 'replace' ); //$learndash_assets_loaded['styles']['wpProQuiz_front_style'] = __FUNCTION__; $filepath = SFWD_LMS::get_template( 'learndash_quiz_front.css', null, null, true ); if ( !empty( $filepath ) ) { wp_enqueue_style( 'learndash_quiz_front_css', learndash_template_url_from_path( $filepath ), array(), LEARNDASH_SCRIPT_VERSION_TOKEN ); wp_style_add_data( 'learndash_quiz_front_css', 'rtl', 'replace' ); $learndash_assets_loaded['styles']['learndash_quiz_front_css'] = __FUNCTION__; } $view = new WpProQuiz_View_StyleManager(); $view->show(); } } lib/controller/WpProQuiz_Controller_Front.php 0000666 00000023602 15214236625 0015516 0 ustar 00 loadSettings(); add_action('wp_enqueue_scripts', array($this, 'loadDefaultScripts')); add_shortcode('LDAdvQuiz', array($this, 'shortcode')); add_shortcode('LDAdvQuiz_toplist', array($this, 'shortcodeToplist')); } public function loadDefaultScripts() { global $learndash_assets_loaded; wp_enqueue_script('jquery'); //wp_enqueue_style( // 'wpProQuiz_front_style', // plugins_url('css/wpProQuiz_front' . leardash_min_asset() .'.css', WPPROQUIZ_FILE), // array(), // LEARNDASH_SCRIPT_VERSION_TOKEN //); //wp_style_add_data( 'wpProQuiz_front_style', 'rtl', 'replace' ); //$learndash_assets_loaded['styles']['wpProQuiz_front_style'] = __FUNCTION__; $filepath = SFWD_LMS::get_template( 'learndash_quiz_front.css', null, null, true ); if ( !empty( $filepath ) ) { wp_enqueue_style( 'learndash_quiz_front_css', learndash_template_url_from_path( $filepath ), array(), LEARNDASH_SCRIPT_VERSION_TOKEN ); wp_style_add_data( 'learndash_quiz_front_css', 'rtl', 'replace' ); $learndash_assets_loaded['styles']['learndash_quiz_front_css'] = __FUNCTION__; } if($this->_settings->isJsLoadInHead()) { $this->loadJsScripts(false, true, true); } } private function loadJsScripts($footer = true, $quiz = true, $toplist = false) { global $learndash_assets_loaded; if ($quiz) { wp_enqueue_script( 'wpProQuiz_front_javascript', plugins_url('js/wpProQuiz_front' . leardash_min_asset() .'.js', WPPROQUIZ_FILE), array('jquery', 'jquery-ui-sortable'), LEARNDASH_SCRIPT_VERSION_TOKEN, $footer ); $learndash_assets_loaded['scripts']['wpProQuiz_front_javascript'] = __FUNCTION__; wp_localize_script('wpProQuiz_front_javascript', 'WpProQuizGlobal', array( 'ajaxurl' => str_replace(array("http:", "https:"), array("",""), admin_url('admin-ajax.php')), 'loadData' => esc_html__('Loading', 'learndash'), 'questionNotSolved' => esc_html__('You must answer this question.', 'learndash'), 'questionsNotSolved' => sprintf( esc_html_x('You must answer all questions before you can complete the %s.', 'You must answer all questions before you can complete the quiz.', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ), 'fieldsNotFilled' => esc_html__('All fields have to be filled.', 'learndash') )); wp_enqueue_script( 'jquery-cookie', plugins_url('js/jquery.cookie' . leardash_min_asset() .'.js', WPPROQUIZ_FILE), array('jquery', 'jquery-ui-sortable'), '1.4.0', $footer ); $learndash_assets_loaded['scripts']['jquery-cookie'] = __FUNCTION__; } if ($toplist) { wp_enqueue_script( 'wpProQuiz_front_javascript_toplist', plugins_url('js/wpProQuiz_toplist'. leardash_min_asset() .'.js', WPPROQUIZ_FILE), array('jquery', 'jquery-ui-sortable'), LEARNDASH_SCRIPT_VERSION_TOKEN, $footer ); $learndash_assets_loaded['scripts']['wpProQuiz_front_javascript_toplist'] = __FUNCTION__; if (!wp_script_is('wpProQuiz_front_javascript') ) { wp_localize_script( 'wpProQuiz_front_javascript_toplist', 'WpProQuizGlobal', array( 'ajaxurl' => str_replace(array("http:", "https:"), array("",""), admin_url('admin-ajax.php')), 'loadData' => esc_html__('Loading', 'learndash'), 'questionNotSolved' => esc_html__('You must answer this question.', 'learndash'), 'questionsNotSolved' => sprintf( esc_html_x('You must answer all questions before you can complete the %s.', 'You must answer all questions before you can complete the quiz.', 'learndash'), learndash_get_custom_label_lower( 'quiz' )), 'fieldsNotFilled' => esc_html__('All fields have to be filled.', 'learndash') ) ); } } if(!$this->_settings->isTouchLibraryDeactivate()) { wp_enqueue_script( 'jquery-ui-touch-punch', plugins_url('js/jquery.ui.touch-punch.min.js', WPPROQUIZ_FILE), array('jquery', 'jquery-ui-sortable'), '0.2.2', $footer ); $learndash_assets_loaded['scripts']['jquery-ui-touch-punch'] = __FUNCTION__; } } public function shortcode($attr = array(), $content = '' ) { global $learndash_shortcode_used, $learndash_shortcode_atts; $learndash_shortcode_used = true; if ( ( isset( $attr[0] ) ) && ( ! empty( $attr[0] ) ) ) { if ( ! isset( $attr['quiz_pro_id'] ) ) { $attr['quiz_pro_id'] = intval( $attr[0] ); unset( $attr[0] ); } } $attr = shortcode_atts( array( 'quiz_id' => 0, 'course_id' => 0, 'lesson_id' => 0, 'topic_id' => 0, 'quiz_pro_id' => 0, ), $attr ); // Just to ensure compliance. $attr['quiz_id'] = absint( $attr['quiz_id'] ); $attr['course_id'] = absint( $attr['course_id'] ); $attr['lesson_id'] = absint( $attr['lesson_id'] ); $attr['topic_id'] = absint( $attr['topic_id'] ); $attr['quiz_pro_id'] = absint( $attr['quiz_pro_id'] ); if ( ! $this->_settings->isJsLoadInHead() ) { $this->loadJsScripts(); } if ( ! empty( $attr['quiz_pro_id'] ) ) { ob_start(); $learndash_shortcode_atts['LDAdvQuiz'] = $attr; $this->handleShortCode( $attr ); $content = ob_get_contents(); ob_end_clean(); } if($this->_settings->isAddRawShortcode()) { return '[raw]'.$content.'[/raw]'; } return $content; } public function handleShortCode( $atts = array() ) { $atts = shortcode_atts( array( 'quiz_id' => 0, 'course_id' => 0, 'lesson_id' => 0, 'topic_id' => 0, 'quiz_pro_id' => 0, ), $atts ); // Just to ensure compliance. $atts['quiz_id'] = absint( $atts['quiz_id'] ); $atts['course_id'] = absint( $atts['course_id'] ); $atts['lesson_id'] = absint( $atts['lesson_id'] ); $atts['topic_id'] = absint( $atts['topic_id'] ); $atts['quiz_pro_id'] = absint( $atts['quiz_pro_id'] ); $view = new WpProQuiz_View_FrontQuiz(); $view->set_shortcode_atts( $atts ); $quizMapper = new WpProQuiz_Model_QuizMapper(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $quiz = $quizMapper->fetch( $atts['quiz_pro_id'] ); $quiz_post_id = $quiz->getPostId(); if ( ( ! empty( $atts['quiz_id'] ) ) && ( intval( $quiz_post_id ) !== intval( $atts['quiz_id'] ) ) ) { $quiz->setPostId( intval( $atts['quiz_id'] ) ); } $maxQuestion = false; if ( ( $quiz->isShowMaxQuestion() ) && ( $quiz->getShowMaxQuestionValue() > 0 ) ) { $value = $quiz->getShowMaxQuestionValue(); if ( $quiz->isShowMaxQuestionPercent() ) { $count = $questionMapper->count( $atts['quiz_pro_id'] ); $value = ceil( $count * $value / 100 ); } //$question = $questionMapper->fetchAll( $atts['quiz_pro_id'], true, $value ); $question = $questionMapper->fetchAll( $quiz, true, $value ); $maxQuestion = true; } else { //$question = $questionMapper->fetchAll( $atts['quiz_pro_id'] ); $question = $questionMapper->fetchAll( $quiz ); } if ( ( empty( $quiz ) ) || ( empty( $question ) ) ) { echo ''; return; } $view->quiz = $quiz; $view->question = $question; $view->category = $categoryMapper->fetchByQuiz( $quiz ); $view->forms = $formMapper->fetch( $atts['quiz_pro_id'] ); if ( $maxQuestion ) { $view->showMaxQuestion(); } else { $view->show(); } } public function shortcodeToplist($attr) { global $learndash_shortcode_used; $learndash_shortcode_used = true; $id = $attr[0]; $content = ''; if(!$this->_settings->isJsLoadInHead()) { $this->loadJsScripts(true, false, true); } if(is_numeric($id)) { ob_start(); $this->handleShortCodeToplist($id, isset($attr['q'])); $content = ob_get_contents(); ob_end_clean(); } if($this->_settings->isAddRawShortcode() && !isset($attr['q'])) { return '[raw]'.$content.'[/raw]'; } return $content; } private function handleShortCodeToplist($quizId, $inQuiz = false) { $quizMapper = new WpProQuiz_Model_QuizMapper(); $view = new WpProQuiz_View_FrontToplist(); $quiz = $quizMapper->fetch($quizId); if($quiz->getId() <= 0 || !$quiz->isToplistActivated()) { echo ''; return; } $view->quiz = $quiz; $view->points = $quizMapper->sumQuestionPoints($quizId); $view->inQuiz = $inQuiz; $view->show(); } private function loadSettings() { $mapper = new WpProQuiz_Model_GlobalSettingsMapper(); $this->_settings = $mapper->fetchAll(); } public static function ajaxQuizLoadData($data, $func) { if (is_user_logged_in() ) $user_id = get_current_user_id(); else $user_id = 0; if ( isset( $data['quizId'] ) ) $id = $data['quizId']; else $id = 0; if ( isset( $data['quiz'] ) ) $quiz_post_id = $data['quiz']; else $quiz_post_id = 0; if ( ( !isset( $data['quiz_nonce'] ) ) || ( !wp_verify_nonce( $data['quiz_nonce'], 'sfwd-quiz-nonce-' . $quiz_post_id . '-'. $id .'-'. $user_id ) ) ) { //wp_send_json_error(); die(); } $view = new WpProQuiz_View_FrontQuiz(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $quiz = $quizMapper->fetch($id); $quiz->setPostId( absint( $quiz_post_id ) ); if ( $quiz->isShowMaxQuestion() && $quiz->getShowMaxQuestionValue() > 0) { $value = $quiz->getShowMaxQuestionValue(); if($quiz->isShowMaxQuestionPercent()) { $count = $questionMapper->count($id); $value = ceil($count * $value / 100); } $question = $questionMapper->fetchAll( $quiz, true, $value ); } else { $question = $questionMapper->fetchAll($quiz); } if(empty($quiz) || empty($question)) { return null; } $view->quiz = $quiz; $view->question = $question; $view->category = $categoryMapper->fetchByQuiz( $quiz ); $view->forms = $formMapper->fetch($quiz->getId()); return json_encode($view->getQuizData()); } } lib/controller/WpProQuiz_Controller_Template.php 0000666 00000001406 15214236625 0016177 0 ustar 00 updateName($template->getTemplateId(), $template->getName()); return json_encode(array()); } public static function ajaxDeleteTemplate($data, $func) { if(!current_user_can('wpProQuiz_edit_quiz')) { return json_encode(array()); } $templateMapper = new WpProQuiz_Model_TemplateMapper(); $template = new WpProQuiz_Model_Template($data); $templateMapper->delete($template->getTemplateId()); return json_encode(array()); } } lib/controller/WpProQuiz_Controller_Admin.php 0000666 00000024065 15214236625 0015462 0 ustar 00 _ajax = new WpProQuiz_Controller_Ajax(); $this->_ajax->init(); //deprecated - use WpProQuiz_Controller_Ajax add_action('wp_ajax_wp_pro_quiz_update_sort', array($this, 'updateSort')); add_action('wp_ajax_wp_pro_quiz_load_question', array($this, 'updateSort')); add_action('wp_ajax_wp_pro_quiz_reset_lock', array($this, 'resetLock')); add_action('wp_ajax_wp_pro_quiz_load_toplist', array($this, 'adminToplist')); add_action('wp_ajax_wp_pro_quiz_completed_quiz', array($this, 'completedQuiz')); add_action('wp_ajax_nopriv_wp_pro_quiz_completed_quiz', array($this, 'completedQuiz')); add_action('wp_ajax_wp_pro_quiz_check_lock', array($this, 'quizCheckLock')); add_action('wp_ajax_nopriv_wp_pro_quiz_check_lock', array($this, 'quizCheckLock')); //0.19 add_action('wp_ajax_wp_pro_quiz_add_toplist', array($this, 'addInToplist')); add_action('wp_ajax_nopriv_wp_pro_quiz_add_toplist', array($this, 'addInToplist')); add_action('wp_ajax_wp_pro_quiz_show_front_toplist', array($this, 'showFrontToplist')); add_action('wp_ajax_nopriv_wp_pro_quiz_show_front_toplist', array($this, 'showFrontToplist')); add_action('wp_ajax_wp_pro_quiz_load_quiz_data', array($this, 'loadQuizData')); add_action('wp_ajax_nopriv_wp_pro_quiz_load_quiz_data', array($this, 'loadQuizData')); add_action('admin_menu', array($this, 'register_page')); } public function loadQuizData() { $q = new WpProQuiz_Controller_Quiz(); echo json_encode($q->loadQuizData()); exit; } public function adminToplist() { $t = new WpProQuiz_Controller_Toplist(); $t->route(); exit; } public function showFrontToplist() { $t = new WpProQuiz_Controller_Toplist(); $t->showFrontToplist(); exit; } public function addInToplist() { $t = new WpProQuiz_Controller_Toplist(); $t->addInToplist(); exit; } public function resetLock() { if ( ( isset( $_GET['post'] ) ) && ( !isset( $_GET['id'] ) ) ) { $_GET['id'] = get_post_meta( $_GET['post'], 'quiz_pro_id', true ); } $c = new WpProQuiz_Controller_Quiz(); $c->route(); } public function quizCheckLock() { $quizController = new WpProQuiz_Controller_Quiz(); echo json_encode($quizController->isLockQuiz($_POST['quizId'])); exit; } public function updateSort() { $c = new WpProQuiz_Controller_Question(); $c->route(); } public function completedQuiz() { // First we unpack the $_POST['results'] string if ( ( isset( $_POST['results'] ) ) && ( !empty( $_POST['results'] ) ) && ( is_string( $_POST['results'] ) ) ) { $_POST['results'] = json_decode(stripslashes($_POST['results']), true); } if ( is_user_logged_in() ) $user_id = get_current_user_id(); else $user_id = 0; if ( isset( $_POST['quizId'] ) ) $id = $_POST['quizId']; else $id = 0; if ( isset( $_POST['quiz'] ) ) $quiz_post_id = $_POST['quiz']; else $quiz_post_id = 0; // LD 2.4.3 - Change in logic. Instead of accepting the values for points, correct etc from JS we now pass the 'results' array on the complete quiz // AJAX action. This now let's us verify the points, correct answers etc. as each have a unique nonce. $total_awarded_points = 0; $total_correct = 0; // If the results is not present then abort. if ( !isset( $_POST['results'] ) ) { return array('text' => esc_html__('An error has occurred.', 'learndash'), 'clear' => true); } // Loop over the 'results' items. We verify and tally the points+correct counts as well as the student response 'data'. When we get to the 'comp' results element // we set the award points and correct as well as determine the total possible points. // @TODO Need to test how this works with variabel question quizzes. foreach( $_POST['results'] as $r_idx => $result ) { if ( $r_idx == 'comp' ) { $_POST['results'][$r_idx]['points'] = intval( $total_awarded_points ); $_POST['results'][$r_idx]['correctQuestions'] = intval( $total_correct ); //$quizMapper = new WpProQuiz_Model_QuizMapper(); //$total_possible_points = $quizMapper->sumQuestionPoints( $id ); //$_POST['results'][$r_idx]['possiblePoints'] = intval( $total_possible_points ); //$_POST['results'][$r_idx]['result'] = round( intval( $_POST['results'][$r_idx]['points'] ) / intval( $_POST['results'][$r_idx]['possiblePoints'] ) * 100, 2 ); continue; } $points_array = array( 'points' => intval( $result['points'] ), 'correct' => intval( $result['correct'] ), 'possiblePoints' => intval( $result['possiblePoints'] ) ); if ( $points_array['correct'] === false ) $points_array['correct'] = 0; else if ( $points_array['correct'] === true ) $points_array['correct'] = 1; $points_str = maybe_serialize( $points_array ); if ( !wp_verify_nonce( $result['p_nonce'], 'ld_quiz_pnonce'. $user_id .'_'. $id .'_'. $quiz_post_id .'_'. $r_idx .'_'. $points_str ) ) { $_POST['results'][$r_idx]['points'] = 0; $_POST['results'][$r_idx]['correct'] = 0; $_POST['results'][$r_idx]['possiblePoints'] = 0; } $total_awarded_points += intval( $_POST['results'][$r_idx]['points'] ); $total_correct += $_POST['results'][$r_idx]['correct']; $response_str = maybe_serialize( $result['data'] ); if ( !wp_verify_nonce( $result['a_nonce'], 'ld_quiz_anonce'. $user_id .'_'. $id .'_'. $quiz_post_id .'_'. $r_idx .'_'. $response_str ) ) { $_POST['results'][$r_idx]['data'] = array(); } } $quiz = new WpProQuiz_Controller_Quiz(); $quiz->completedQuiz(); } private function localizeScript() { global $wp_locale; $isRtl = isset($wp_locale->is_rtl) ? $wp_locale->is_rtl : false; $translation_array = array( 'delete_msg' => sprintf( esc_html_x('Do you really want to delete the %s/question?', 'Do you really want to delete the quiz/question?', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ), 'no_title_msg' => esc_html__('Title is not filled!', 'learndash'), 'no_question_msg' => esc_html__('No question deposited!', 'learndash'), 'no_correct_msg' => esc_html__('Correct answer was not selected!', 'learndash'), 'no_answer_msg' => esc_html__('No answer deposited!', 'learndash'), 'no_quiz_start_msg' => sprintf( esc_html_x('No %s description filled!', 'No quiz description filled!', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ), 'fail_grade_result' => esc_html__('The percent values in result text are incorrect.', 'learndash'), 'no_nummber_points' => esc_html__('No number in the field "Points" or less than 1', 'learndash'), 'no_nummber_points_new' => esc_html__('No number in the field "Points" or less than 0', 'learndash'), 'no_selected_quiz' => sprintf( esc_html_x('No %s selected', 'No quiz selected', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ), 'reset_statistics_msg' => esc_html__('Do you really want to reset the statistic?', 'learndash'), 'no_data_available' => esc_html__('No data available', 'learndash'), 'no_sort_element_criterion' => esc_html__('No sort element in the criterion', 'learndash'), 'dif_points' => esc_html__('"Different points for every answer" is not possible at "Free" choice', 'learndash'), 'category_no_name' => esc_html__('You must specify a name.', 'learndash'), 'confirm_delete_entry' => esc_html__('This entry should really be deleted?', 'learndash'), 'not_all_fields_completed' => esc_html__('Not all fields completed.', 'learndash'), 'temploate_no_name' => esc_html__('You must specify a template name.', 'learndash'), 'no_delete_answer' => esc_html__('Cannot delete only answer', 'learndash'), 'closeText' => esc_html__('Close', 'learndash'), 'currentText' => esc_html__('Today', 'learndash'), 'monthNames' => array_values($wp_locale->month), 'monthNamesShort' => array_values($wp_locale->month_abbrev), 'dayNames' => array_values($wp_locale->weekday), 'dayNamesShort' => array_values($wp_locale->weekday_abbrev), 'dayNamesMin' => array_values($wp_locale->weekday_initial), 'dateFormat' => WpProQuiz_Helper_Until::convertPHPDateFormatToJS(get_option('date_format', 'm/d/Y')), 'firstDay' => get_option('start_of_week'), 'isRTL' => $isRtl ); wp_localize_script('wpProQuiz_admin_javascript', 'wpProQuizLocalize', $translation_array); } public function enqueueScript() { global $learndash_assets_loaded; wp_enqueue_script( 'wpProQuiz_admin_javascript', plugins_url('js/wpProQuiz_admin'. leardash_min_asset() .'.js', WPPROQUIZ_FILE), array('jquery', 'jquery-ui-sortable', 'jquery-ui-datepicker'), LEARNDASH_SCRIPT_VERSION_TOKEN ); $learndash_assets_loaded['scripts']['wpProQuiz_admin_javascript'] = __FUNCTION__; $this->localizeScript(); } public function register_page() { $quiz_title = sprintf( esc_html_x('Advanced %s', 'Advanced Quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ); $page = add_submenu_page( "edit.php?post_type=sfwd-quiz", $quiz_title, $quiz_title, "wpProQuiz_show", "ldAdvQuiz", array($this, 'route') ); add_action('admin_print_scripts-'.$page, array($this, 'enqueueScript')); } public function route() { $module = isset($_GET['module']) ? $_GET['module'] : 'overallView'; $c = null; switch ($module) { case 'overallView': $c = new WpProQuiz_Controller_Quiz(); break; case 'question': $c = new WpProQuiz_Controller_Question(); break; case 'preview': $c = new WpProQuiz_Controller_Preview(); break; case 'statistics': $c = new WpProQuiz_Controller_Statistics(); break; case 'importExport': $c = new WpProQuiz_Controller_ImportExport(); break; case 'globalSettings': $c = new WpProQuiz_Controller_GlobalSettings(); break; case 'styleManager': $c = new WpProQuiz_Controller_StyleManager(); break; case 'toplist': $c = new WpProQuiz_Controller_Toplist(); break; case 'wpq_support': $c = new WpProQuiz_Controller_WpqSupport(); break; } if($c !== null) { $c->route(); } } } lib/controller/WpProQuiz_Controller_Controller.php 0000666 00000000541 15214236625 0016546 0 ustar 00 _post === null) { $this->_post = stripslashes_deep($_POST); } if($this->_cookie === null && $_COOKIE !== null) { $this->_cookie = stripslashes_deep($_COOKIE); } } } lib/controller/WpProQuiz_Controller_Category.php 0000666 00000002253 15214236625 0016202 0 ustar 00 save( $category ); return json_encode( array( 'categoryId' => $category->getCategoryId(), 'categoryName' => stripslashes( $category->getCategoryName() ), ) ); } public static function ajaxEditCategory($data, $func) { if(!current_user_can('wpProQuiz_edit_quiz')) { return json_encode(array()); } $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $category = new WpProQuiz_Model_Category($data); $categoryMapper->save($category); return json_encode(array()); } public static function ajaxDeleteCategory($data, $func) { if(!current_user_can('wpProQuiz_edit_quiz')) { return json_encode(array()); } $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $category = new WpProQuiz_Model_Category($data); $categoryMapper->delete($category->getCategoryId()); return json_encode(array()); } } lib/controller/WpProQuiz_Controller_Preview.php 0000666 00000005424 15214236625 0016051 0 ustar 00 str_replace(array("http:", "https:"), array("",""), admin_url('admin-ajax.php')), 'loadData' => esc_html__('Loading', 'learndash'), 'questionNotSolved' => esc_html__('You must answer this question.', 'learndash'), 'questionsNotSolved' => sprintf( esc_html_x('You must answer all questions before you can complete the %s.', 'You must answer all questions before you can complete the quiz.', 'learndash'), learndash_get_custom_label_lower( 'quiz' ) ), 'fieldsNotFilled' => esc_html__('All fields have to be filled.', 'learndash') )); //wp_enqueue_style( // 'wpProQuiz_front_style', // plugins_url('css/wpProQuiz_front'. leardash_min_asset() .'.css', WPPROQUIZ_FILE), // array(), // LEARNDASH_SCRIPT_VERSION_TOKEN //); //wp_style_add_data( 'wpProQuiz_front_style', 'rtl', 'replace' ); //$learndash_assets_loaded['styles']['wpProQuiz_front_style'] = __FUNCTION__; $filepath = SFWD_LMS::get_template( 'learndash_quiz_front.css', null, null, true ); if ( !empty( $filepath ) ) { wp_enqueue_style( 'learndash_quiz_front_css', learndash_template_url_from_path( $filepath ), array(), LEARNDASH_SCRIPT_VERSION_TOKEN ); wp_style_add_data( 'learndash_quiz_front_css', 'rtl', 'replace' ); $learndash_assets_loaded['styles']['learndash_quiz_front_css'] = __FUNCTION__; } $this->showAction($_GET['id']); } public function showAction($id) { $view = new WpProQuiz_View_FrontQuiz(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $quiz = $quizMapper->fetch($id); if($quiz->isShowMaxQuestion() && $quiz->getShowMaxQuestionValue() > 0) { $value = $quiz->getShowMaxQuestionValue(); if($quiz->isShowMaxQuestionPercent()) { $count = $questionMapper->count($id); $value = ceil($count * $value / 100); } $question = $questionMapper->fetchAll($quiz, true, $value); } else { $question = $questionMapper->fetchAll($id); } $view->quiz = $quiz; $view->question = $question; $view->category = $categoryMapper->fetchByQuiz( $quiz ); $view->forms = $formMapper->fetch($quiz->getId()); $view->show(true); } } lib/controller/WpProQuiz_Controller_QuizCompleted.php 0000666 00000022567 15214236625 0017224 0 ustar 00 data = $data; } public static function ajaxQuizCompleted($data, $func) { $completed = new WpProQuiz_Controller_QuizCompleted($data); return $completed->quizCompleted(); } public function quizCompleted() { $lockMapper = new WpProQuiz_Model_LockMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $statistics = new WpProQuiz_Controller_Statistics(); $quiz = $quizMapper->fetch($this->data['quizId']); if($quiz === null || $quiz->getId() <= 0) { return; } $categories = $categoryMapper->fetchByQuiz( $quiz ); $userId = get_current_user_id(); $resultInPercent = floor($this->data['results']['comp']['result']); $this->setResultCookie($quiz); $this->emailNote($quiz, $this->data['results']['comp'], $categories); if(!$this->isPreLockQuiz($quiz)) { $statistics->save(); do_action('wp_pro_quiz_completed_quiz'); do_action('wp_pro_quiz_completed_quiz_'.$resultInPercent.'_percent'); return; } $lockMapper->deleteOldLock(60*60*24*7, $this->_post['quizId'], time(), WpProQuiz_Model_Lock::TYPE_QUIZ, 0); $lockIp = $lockMapper->isLock($this->_post['quizId'], $this->getIp(), get_current_user_id(), WpProQuiz_Model_Lock::TYPE_QUIZ); $lockCookie = false; $cookieTime = $quiz->getQuizRunOnceTime(); $cookieJson = null; if(isset($this->_cookie['wpProQuiz_lock']) && get_current_user_id() == 0 && $quiz->isQuizRunOnceCookie()) { $cookieJson = json_decode($this->_cookie['wpProQuiz_lock'], true); if($cookieJson !== false) { if(isset($cookieJson[$this->_post['quizId']]) && $cookieJson[$this->_post['quizId']] == $cookieTime) { $lockCookie = true; } } } if(!$lockIp && !$lockCookie) { $statistics->save(); do_action('wp_pro_quiz_completed_quiz'); do_action('wp_pro_quiz_completed_quiz_'.$resultInPercent.'_percent'); if(get_current_user_id() == 0 && $quiz->isQuizRunOnceCookie()) { $cookieData = array(); if($cookieJson !== null || $cookieJson !== false) { $cookieData = $cookieJson; } $cookieData[$this->_post['quizId']] = $quiz->getQuizRunOnceTime(); $url = parse_url(get_bloginfo( 'url' )); setcookie('wpProQuiz_lock', json_encode($cookieData), time() + 60*60*24*60, empty($url['path']) ? '/' : $url['path']); } $lock = new WpProQuiz_Model_Lock(); $lock->setUserId(get_current_user_id()); $lock->setQuizId($this->_post['quizId']); $lock->setLockDate(time()); $lock->setLockIp($this->getIp()); $lock->setLockType(WpProQuiz_Model_Lock::TYPE_QUIZ); $lockMapper->insert($lock); } return; } private function setResultCookie(WpProQuiz_Model_Quiz $quiz) { $prerequisite = new WpProQuiz_Model_PrerequisiteMapper(); if(get_current_user_id() == 0 && $prerequisite->isQuizId($quiz->getId())) { $cookieData = array(); if(isset($this->_cookie['wpProQuiz_result'])) { $d = json_decode($this->_cookie['wpProQuiz_result'], true); if($d !== null && is_array($d)) { $cookieData = $d; } } $cookieData[$quiz->getId()] = 1; $url = parse_url(get_bloginfo( 'url' )); setcookie('wpProQuiz_result', json_encode($cookieData), time() + 60*60*24*300, empty($url['path']) ? '/' : $url['path']); } } private function emailNote(WpProQuiz_Model_Quiz $quiz, $result, $categories) { $globalMapper = new WpProQuiz_Model_GlobalSettingsMapper(); $adminEmail = $globalMapper->getEmailSettings(); $userEmail = $globalMapper->getUserEmailSettings(); $user = wp_get_current_user(); $r = array( '$userId' => $user->ID, '$username' => $user->display_name, '$quizname' => $quiz->getName(), '$result' => $result['result'].'%', '$points' => $result['points'], '$ip' => filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP), '$categories' => empty($result['cats']) ? '' : $this->setCategoryOverview($result['cats'], $categories) ); if($user->ID == 0) { $r['$username'] = $r['$ip']; } if($quiz->isUserEmailNotification()) { $msg = str_replace(array_keys($r), $r, $userEmail['message']); $headers = ''; //if(!empty($userEmail['from'])) { // $headers = 'From: '.$userEmail['from']; //} if ( ( isset( $userEmail['from'] ) ) && ( !empty( $userEmail['from'] ) ) && ( is_email( $userEmail['from'] ) ) ) { if ( ( !isset( $userEmail['from_name'] ) ) || ( empty( $userEmail['from_name'] ) ) ) { $userEmail['from_name'] = ''; $email_user = get_user_by('emal', $userEmail['from'] ); if ( ( $email_user ) && ( $email_user instanceof WP_User ) ) { $userEmail['from_name'] = $email_user->display_name; } } $headers .= 'From: '; if ( ( isset( $userEmail['from_name'] ) ) && ( !empty( $userEmail['from_name'] ) ) ) { $headers .= $userEmail['from_name'] .' <'. $userEmail['from'] .'>'; } else { $headers .= $userEmail['from']; } } if($userEmail['html']) add_filter('wp_mail_content_type', array($this, 'htmlEmailContent')); $email_params = array( "email" => $user->user_email, "subject" => $userEmail['subject'], "msg" => $msg, "headers" => $headers ); $email_params = apply_filters("learndash_quiz_completed_email", $email_params, $quiz); wp_mail($email_params["email"], $email_params["subject"], $email_params["msg"], $email_params["headers"]); if($userEmail['html']) remove_filter('wp_mail_content_type', array($this, 'htmlEmailContent')); } if($quiz->getEmailNotification() == WpProQuiz_Model_Quiz::QUIZ_EMAIL_NOTE_ALL || (get_current_user_id() > 0 && $quiz->getEmailNotification() == WpProQuiz_Model_Quiz::QUIZ_EMAIL_NOTE_REG_USER)) { $msg = str_replace(array_keys($r), $r, $adminEmail['message']); $headers = ''; //if(!empty($adminEmail['from'])) { // $headers = 'From: '.$adminEmail['from']; //} if ( ( !isset( $adminEmail['from'] ) ) || ( empty( $adminEmail['from'] ) ) || ( !is_email( $adminEmail['from'] ) ) ) { $adminEmail['from'] = get_option( 'admin_email' ); } if ( ( !isset( $adminEmail['from_name'] ) ) || ( empty( $adminEmail['from_name'] ) ) ) { $adminEmail['from_name'] = ''; if ( !empty( $adminEmail['from'] ) ) { $email_user = get_user_by('emal', $adminEmail['from'] ); if ( ( $email_user ) && ( $email_user instanceof WP_User ) ) { $adminEmail['from_name'] = $email_user->display_name; } } } if ( !empty( $adminEmail['from'] ) ) { $headers .= 'From: '; if ( ( isset( $adminEmail['from_name'] ) ) && ( !empty( $adminEmail['from_name'] ) ) ) { $headers .= $adminEmail['from_name'] .' <'. $adminEmail['from'] .'>'; } else { $headers .= $adminEmail['from']; } } if(isset($adminEmail['html']) && $adminEmail['html']) add_filter('wp_mail_content_type', array($this, 'htmlEmailContent')); $email_params = array( "email" => $adminEmail['to'], "subject" => $adminEmail['subject'], "msg" => $msg, "headers" => $headers ); $email_params = apply_filters("learndash_quiz_completed_email_admin", $email_params, $quiz); wp_mail($email_params["email"], $email_params["subject"], $email_params["msg"], $email_params["headers"]); //wp_mail($adminEmail['to'], $adminEmail['subject'], $msg, $headers); if(isset($adminEmail['html']) && $adminEmail['html']) remove_filter('wp_mail_content_type', array($this, 'htmlEmailContent')); } } public function htmlEmailContent($contentType) { return 'text/html'; } private function setCategoryOverview( $category_scores = array() , $question_cats = array() ) { if ( ( ! empty( $category_scores ) ) && ( ! empty( $question_cats ) ) ) { $question_categories = array(); foreach ( $question_cats as $cat ) { if ( ! $cat->getCategoryId() ) { $cat->setCategoryName( esc_html__( 'Not categorized', 'learndash' ) ); } $question_categories[ $cat->getCategoryId() ] = $cat->getCategoryName(); } } $output = SFWD_LMS::get_template( 'quiz_result_categories_email.php', array( 'question_categories' => $question_categories, 'category_scores' => $category_scores, ) ); return $output; //$cats = array(); // //foreach($categories as $cat) { // /* @var $cat WpProQuiz_Model_Category */ // // if(!$cat->getCategoryId()) { // $cat->setCategoryName(__('Not categorized', 'learndash')); // } // // $cats[$cat->getCategoryId()] = $cat->getCategoryName(); //} // //$a = esc_html__('Categories', 'learndash').":\n"; // //foreach($catArray as $id => $value) { // if(!isset($cats[$id])) // continue; // // $a .= '* '.str_pad($cats[$id], 35, '.').((float)$value)."%\n"; //} // //return $a; } private function isPreLockQuiz(WpProQuiz_Model_Quiz $quiz) { $userId = get_current_user_id(); if($quiz->isQuizRunOnce()) { switch ($quiz->getQuizRunOnceType()) { case WpProQuiz_Model_Quiz::QUIZ_RUN_ONCE_TYPE_ALL: return true; case WpProQuiz_Model_Quiz::QUIZ_RUN_ONCE_TYPE_ONLY_USER: return $userId > 0; case WpProQuiz_Model_Quiz::QUIZ_RUN_ONCE_TYPE_ONLY_ANONYM: return $userId == 0; } } return false; } private function getIp() { if(get_current_user_id() > 0) return '0'; else return filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); } } lib/controller/WpProQuiz_Controller_Ajax.php 0000666 00000004614 15214236625 0015313 0 ustar 00 initCallbacks(); add_action('wp_ajax_wp_pro_quiz_admin_ajax', array($this, 'adminAjaxCallback')); add_action('wp_ajax_nopriv_wp_pro_quiz_admin_ajax', array($this, 'frontAjaxCallback')); } public function adminAjaxCallback() { $this->ajaxCallbackHandler(true); } public function frontAjaxCallback() { $this->ajaxCallbackHandler(false); } private function ajaxCallbackHandler($admin) { $func = isset($_POST['func']) ? $_POST['func'] : ''; $data = isset($_POST['data']) ? $_POST['data'] : null; $calls = $admin ? $this->_adminCallbacks : $this->_frontCallbacks; if(isset($calls[$func])) { $r = call_user_func($calls[$func], $data, $func); if($r !== null) echo $r; } exit; } private function initCallbacks() { $this->_adminCallbacks = array( 'categoryAdd' => array('WpProQuiz_Controller_Category', 'ajaxAddCategory'), 'categoryDelete' => array('WpProQuiz_Controller_Category', 'ajaxDeleteCategory'), 'categoryEdit' => array('WpProQuiz_Controller_Category', 'ajaxEditCategory'), 'statisticLoad' => array('WpProQuiz_Controller_Statistics', 'ajaxLoadStatistic'), /** @deprecated **/ 'statisticLoadOverview' => array('WpProQuiz_Controller_Statistics', 'ajaxLoadStatsticOverview'), /** @deprecated **/ 'statisticReset' => array('WpProQuiz_Controller_Statistics', 'ajaxReset'), /** @deprecated **/ 'statisticLoadFormOverview' => array('WpProQuiz_Controller_Statistics', 'ajaxLoadFormOverview'), /** @deprecated **/ 'statisticLoadHistory' => array('WpProQuiz_Controller_Statistics', 'ajaxLoadHistory'), 'statisticLoadUser' => array('WpProQuiz_Controller_Statistics', 'ajaxLoadStatisticUser'), 'statisticResetNew' => array('WpProQuiz_Controller_Statistics', 'ajaxRestStatistic'), 'statisticLoadOverviewNew' => array('WpProQuiz_Controller_Statistics', 'ajaxLoadStatsticOverviewNew'), 'templateEdit' => array('WpProQuiz_Controller_Template', 'ajaxEditTemplate'), 'templateDelete' => array('WpProQuiz_Controller_Template', 'ajaxDeleteTemplate'), 'quizLoadData' => array('WpProQuiz_Controller_Front', 'ajaxQuizLoadData') ); //nopriv $this->_frontCallbacks = array( 'quizLoadData' => array('WpProQuiz_Controller_Front', 'ajaxQuizLoadData') ); } } lib/controller/WpProQuiz_Controller_Statistics.php 0000666 00000065702 15214236625 0016567 0 ustar 00 show($_GET['id']); } } public function getAverageResult($quizId) { $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); // $quizMapper = new WpProQuiz_Model_QuizMapper(); // $r = $statisticRefMapper->fetchByQuiz($quizId); // $maxPoints = $quizMapper->sumQuestionPoints($quizId); // $sumQuestion = $quizMapper->countQuestion($quizId); // if($r['count'] > 0) { // return round((100 * $r['points'] / ($r['count'] * $maxPoints / $sumQuestion)), 2); // } $result = $statisticRefMapper->fetchFrontAvg($quizId); if(isset($result['g_points']) && $result['g_points']) return round(100 * $result['points'] / $result['g_points'], 2); return 0; } /** * @deprecated */ private function show($quizId) { if(!current_user_can('wpProQuiz_show_statistics')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $this->showNew($quizId); return; $view = new WpProQuiz_View_Statistics(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $categoryMapper = new WpProQuiz_Model_CategoryMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $quiz = $quizMapper->fetch($quizId); $questions = $questionMapper->fetchAll($quiz); $category = $categoryMapper->fetchAll(); $categoryEmpty = new WpProQuiz_Model_Category(); $categoryEmpty->setCategoryName(__('No category', 'learndash')); $list = array(); $cats = array(); foreach($category as $c) { $cats[$c->getCategoryId()] = $c; } $cats[0] = $categoryEmpty; foreach($questions as $q) { $list[$q->getCategoryId()][] = $q; } $view->quiz = $quizMapper->fetch($quizId); $view->questionList = $list; $view->categoryList = $cats; $view->forms = $formMapper->fetch($quizId); if(has_action('pre_user_query', 'ure_exclude_administrators')) { remove_action('pre_user_query', 'ure_exclude_administrators'); $users = get_users(array('fields' => array('ID','user_login','display_name'))); add_action('pre_user_query', 'ure_exclude_administrators'); } else { $users = get_users(array('fields' => array('ID','user_login','display_name'))); } array_unshift($users, (object)array('ID' => 0)); $view->users = $users; $view->show(); } private function showNew($quizId) { $view = new WpProQuiz_View_StatisticsNew(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $quiz = $quizMapper->fetch($quizId); if(has_action('pre_user_query', 'ure_exclude_administrators')) { remove_action('pre_user_query', 'ure_exclude_administrators'); $users = get_users(array('fields' => array('ID','user_login','display_name'))); add_action('pre_user_query', 'ure_exclude_administrators'); } else { $users = get_users(array('fields' => array('ID','user_login','display_name'))); } $view->quiz = $quiz; $view->users = $users; $view->show(); } /** * * @param WpProQuiz_Model_Quiz $quiz * @return void|boolean */ public function save($quiz = null) { $quizId = $this->_post['quizId']; $array = $this->_post['results']; $lockIp = $this->getIp(); $userId = get_current_user_id(); if($lockIp === false) return false; if($quiz === null) { $quizMapper = new WpProQuiz_Model_QuizMapper(); $quiz = $quizMapper->fetch($quizId); } if(!$quiz->isStatisticsOn()) return false; $values = $this->makeDataList($quiz, $array, $userId, $quiz->getQuizModus()); $formValues = $this->makeFormData($quiz, $userId, isset($this->_post['forms']) ? $this->_post['forms'] : null); if($values === false) return; if($quiz->getStatisticsIpLock() > 0) { $lockMapper = new WpProQuiz_Model_LockMapper(); $lockTime = $quiz->getStatisticsIpLock() * 60; $lockMapper->deleteOldLock($lockTime, $quiz->getId(), time(), WpProQuiz_Model_Lock::TYPE_STATISTIC); if($lockMapper->isLock($quizId, $lockIp, $userId, WpProQuiz_Model_Lock::TYPE_STATISTIC)) return false; $lock = new WpProQuiz_Model_Lock(); $lock ->setQuizId($quizId) ->setLockIp($lockIp) ->setUserId($userId) ->setLockType(WpProQuiz_Model_Lock::TYPE_STATISTIC) ->setLockDate(time()); $lockMapper->insert($lock); } $statisticRefModel = new WpProQuiz_Model_StatisticRefModel(); $statisticRefModel->setCreateTime(time()); $statisticRefModel->setUserId($userId); $statisticRefModel->setQuizId($quizId); $statisticRefModel->setFormData($formValues); $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $statisticRefMapper_id = $statisticRefMapper->statisticSave($statisticRefModel, $values); return $statisticRefMapper_id; } /** * @param WpProQuiz_Model_Quiz $quiz * @param int $userId */ private function makeFormData($quiz, $userId, $data) { if(!$quiz->isFormActivated() || empty($data)) return null; $formMapper = new WpProQuiz_Model_FormMapper(); $forms = $formMapper->fetch($quiz->getId()); if(empty($forms)) return null; $formArray = array(); foreach($forms as $form) { if($form->getType() != WpProQuiz_Model_Form::FORM_TYPE_DATE) { $str = isset($data[$form->getFormId()]) ? $data[$form->getFormId()] : ''; if(WpProQuiz_Helper_Form::valid($form, $str) === false) return null; $formArray[$form->getFormId()] = trim($str); } else { $date = isset($data[$form->getFormId()]) ? $data[$form->getFormId()] : array(); $dateStr = WpProQuiz_Helper_Form::validData($form, $date); if($dateStr === null) return null; $formArray[$form->getFormId()] = $dateStr; } } return $formArray; } private function makeDataList($quiz, $array, $userId, $modus) { $questionMapper = new WpProQuiz_Model_QuestionMapper(); $question = $questionMapper->fetchAllList($quiz, array('id', 'points')); $ids = array(); foreach($question as $q) { if(!isset($array[$q['id']])) continue; $ids[] = $q['id']; $v = $array[$q['id']]; if(!isset($v) || $v['points'] > $q['points'] || $v['points'] < 0) { return false; } } $avgTime = null; if($modus == WpProQuiz_Model_Quiz::QUIZ_MODUS_SINGLE) { $avgTime = ceil($array['comp']['quizTime'] / count($question)); } unset($array['comp']); $ak = array_keys($array); if(array_diff($ids, $ak) !== array_diff($ak, $ids)) return false; $values = array(); foreach($array as $k => $v) { $s = new WpProQuiz_Model_Statistic(); $s->setQuizId($quiz->getId()); $s->setQuestionId($k); $s->setUserId($userId); $s->setHintCount(isset($v['tip']) ? 1 : 0); $s->setCorrectCount($v['correct'] ? 1 : 0); $s->setIncorrectCount($v['correct'] ? 0 : 1); $s->setPoints($v['points']); $s->setQuestionTime($avgTime === null ? $v['time'] : $avgTime); $s->setAnswerData(isset($v['data']) ? $v['data'] : null); $values[] = $s; } return $values; } private function getIp() { if(get_current_user_id() > 0) return '0'; else return filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); } /** * @deprecated */ public static function ajaxLoadStatistic($data, $func) { if(!current_user_can('wpProQuiz_show_statistics')) { return json_encode(array()); } $userId = $data['userId']; $quizId = $data['quizId']; $testId = $data['testId']; $maxPoints = 0; $sumQuestion = 0; $inTest = false; $category = array(); $categoryList = array(); $testJson = array(); $formData = null; $statisticMapper = new WpProQuiz_Model_StatisticMapper(); $questionMapper = new WpProQuiz_Model_QuestionMapper(); $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $tests = $statisticRefMapper->fetchAll($quizId, $userId, $testId); $i = 1; foreach($tests as $test) { if($testId == $test->getStatisticRefId()) $inTest = true; $testJson[] = array( 'id' => $test->getStatisticRefId(), 'date' => '#'.$i++.' '.WpProQuiz_Helper_Until::convertTime( $test->getCreateTime(), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Management_Display', 'statistics_time_format' ) //get_option('wpProQuiz_statisticTimeFormat', 'Y/m/d g:i A') ) ); } if(!$inTest) { $data['testId'] = $testId = 0; } if(!$testId) { $statistics = $statisticRefMapper->fetchAvg($quizId, $userId); } else { $statistics = $statisticMapper->fetchAllByRef($testId); $refModel = $statisticRefMapper->fetchByRefId($testId); $formData = $refModel->getFormData(); } $questionData = $questionMapper->fetchAllList($quizId, array('id', 'category_id', 'points')); $empty = array( 'questionId' => 0, 'correct' => 0, 'incorrect' => 0, 'hint' => 0, 'points' => 0, 'result' => 0, 'questionTime' => 0 ); $ca = $sa = array(); $ga = $empty; foreach($questionData as $cc) { $categoryList[$cc['id']] = $cc['category_id']; $c = &$category[$cc['category_id']]; if(empty($c)) { $c = $cc; $c['sum'] = 1; } else { $c['points'] += $cc['points']; $c['sum']++; } $maxPoints += $cc['points']; $sumQuestion++; $sa[$cc['id']] = self::calcTotal($empty); $sa[$cc['id']]['questionId'] = $cc['id']; $ca[$cc['category_id']] = self::calcTotal($empty); } foreach($statistics as $statistic) { $s = $statistic->getCorrectCount() + $statistic->getIncorrectCount(); if($s > 0) { $correct = $statistic->getCorrectCount().' ('.round((100 * $statistic->getCorrectCount() / $s), 2).'%)'; $incorrect = $statistic->getIncorrectCount().' ('.round((100 * $statistic->getIncorrectCount() / $s), 2).'%)'; } else { $incorrect = $correct = '0 (0%)'; } $ga['correct'] += $statistic->getCorrectCount(); $ga['incorrect'] += $statistic->getIncorrectCount(); $ga['hint'] += $statistic->getHintCount(); $ga['points'] += $statistic->getPoints(); $ga['questionTime'] += $statistic->getQuestionTime(); $cats = &$ca[$categoryList[$statistic->getQuestionId()]]; if(!is_array($cats)) { $cats = $empty; } $cats['correct'] += $statistic->getCorrectCount(); $cats['incorrect'] += $statistic->getIncorrectCount(); $cats['hint'] += $statistic->getHintCount(); $cats['points'] += $statistic->getPoints(); $cats['questionTime'] += $statistic->getQuestionTime(); $sa[$statistic->getQuestionId()] = array( 'questionId' => $statistic->getQuestionId(), 'correct' => $correct, 'incorrect' => $incorrect, 'hint' => $statistic->getHintCount(), 'points' => $statistic->getPoints(), 'questionTime' => self::convertToTimeString($statistic->getQuestionTime()) ); } foreach($ca as $catIndex => $cat) { $ca[$catIndex] = self::calcTotal($cat, $category[$catIndex]['points'], $category[$catIndex]['sum']); } $sa[0] = self::calcTotal($ga, $maxPoints, $sumQuestion); return json_encode(array( 'question' => $sa, 'category' => $ca, 'tests' => $testJson, 'testId' => $data['testId'], 'formData' => $formData )); } /** * @deprecated */ public static function ajaxReset($data, $func) { if(!current_user_can('wpProQuiz_reset_statistics')) { return; } $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $quizId = $data['quizId']; $userId = $data['userId']; $testId = $data['testId']; switch ($data['type']) { case 0: $statisticRefMapper->deleteUserTest($quizId, $userId, $testId); break; case 1: $statisticRefMapper->deleteUser($quizId, $userId); break; case 2: $statisticRefMapper->deleteAll($quizId); break; } } /** * @deprecated */ public static function ajaxLoadStatsticOverview($data, $func) { if(!current_user_can('wpProQuiz_show_statistics')) { return json_encode(array()); } $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $quizId = $data['quizId']; $page = (isset($data['page']) && $data['page'] > 0) ? $data['page'] : 1; $limit = $data['pageLimit']; $start = $limit * ($page - 1); $statistics = $statisticRefMapper->fetchOverview($quizId, (bool)$data['onlyCompleted'], $start, $limit); $d = array('items' => array()); $maxPoints = $quizMapper->sumQuestionPoints($quizId); $sumQuestion = $quizMapper->countQuestion($quizId); foreach($statistics as $statistic) { $sum = $statistic->getCorrectCount() + $statistic->getIncorrectCount(); if($sum > 0) { $correct = $statistic->getCorrectCount().' ('.round((100 * $statistic->getCorrectCount() / $sum), 2).'%)'; $incorrect = $statistic->getIncorrectCount().' ('.round((100 * $statistic->getIncorrectCount() / $sum), 2).'%)'; $hint = $statistic->getHintCount(); $result = round((100 * $statistic->getPoints() / ($sum * $maxPoints / $sumQuestion)), 2).'%'; $points = $statistic->getPoints(); $questionTime = self::convertToTimeString($statistic->getQuestionTime()); } else { $questionTime = $points = $result = $hint = $correct = $incorrect = '---'; } $d['items'][] = array( 'userId' => $statistic->getUserId(), 'userName' => $statistic->getUserName(), 'points' => $points, 'correct' => $correct, 'incorrect' => $incorrect, 'hint' => $hint, 'result' => $result, 'questionTime' => $questionTime ); } if(isset($data['nav']) && $data['nav']) { $count = $statisticRefMapper->countOverview($quizId, (bool)$data['onlyCompleted']); $d['page'] = ceil(($count > 0 ? $count : 1) / $limit); } return json_encode($d); } /** * @deprecated */ private static function calcTotal($a, $maxPoints = null, $sumQuestion = null) { $s = $a['correct'] + $a['incorrect']; if($s > 0) { $a['correct'] = $a['correct'].' ('.round((100 * $a['correct'] / $s), 2).'%)'; $a['incorrect'] = $a['incorrect'].' ('.round((100 * $a['incorrect'] / $s), 2).'%)'; if($maxPoints !== null) $a['result'] = round((100 * $a['points'] / ($s * $maxPoints / $sumQuestion)), 2).'%'; } else { $a['result'] = $a['correct'] = $a['incorrect'] = '0 (0%)'; } $a['questionTime'] = self::convertToTimeString($a['questionTime']); return $a; } /** * @deprecated */ private static function convertToTimeString($s) { $h = floor($s / 3600); $s -= $h * 3600; $m = floor($s / 60); $s -= $m * 60; return sprintf("%02d:%02d:%02d", $h, $m, $s); } /** * @deprecated */ public static function ajaxLoadFormOverview($data, $func) { if(!current_user_can('wpProQuiz_show_statistics')) { return json_encode(array()); } $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $quizId = $data['quizId']; $page = (isset($data['page']) && $data['page'] > 0) ? $data['page'] : 1; $limit = $data['pageLimit']; $start = $limit * ($page - 1); $statisticModel = $statisticRefMapper->fetchFormOverview($quizId, $start, $limit, $data['onlyUser']); $items = array(); $maxPoints = $quizMapper->sumQuestionPoints($quizId); $sumQuestion = $quizMapper->countQuestion($quizId); foreach($statisticModel as $model) { /*@var $model WpProQuiz_Model_StatisticFormOverview */ if(!$model->getUserId()) $model->setUserName(__('Anonymous', 'learndash')); $sum = $model->getCorrectCount() + $model->getIncorrectCount(); $result = round((100 * $model->getPoints() / ($sum * $maxPoints / $sumQuestion)), 2).'%'; $items[] = array( 'userName' => $model->getUserName(), 'userId' => $model->getUserId(), 'testId' => $model->getStatisticRefId(), 'date' => WpProQuiz_Helper_Until::convertTime( $model->getCreateTime(), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Management_Display', 'statistics_time_format' ) //get_option('wpProQuiz_statisticTimeFormat', 'Y/m/d g:i A') ), 'result' => $result ); } $d = array('items' => $items); if(isset($data['nav']) && $data['nav']) { $count = $statisticRefMapper->countFormOverview($quizId, $data['onlyUser']); $d['page'] = ceil(($count > 0 ? $count : 1) / $limit); } return json_encode($d); } public static function ajaxLoadHistory($data, $func) { if(!current_user_can('wpProQuiz_show_statistics')) { return json_encode(array()); } $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $quizId = $data['quizId']; $page = (isset($data['page']) && $data['page'] > 0) ? $data['page'] : 1; $limit = $data['pageLimit']; $start = $limit * ($page - 1); $startTime = (int)$data['dateFrom']; $endTime = (int)$data['dateTo'] ? $data['dateTo'] + 86400 : 0; $statisticModel = $statisticRefMapper->fetchHistory($quizId, $start, $limit, $data['users'], $startTime, $endTime); foreach($statisticModel as $model) { /*@var $model WpProQuiz_Model_StatisticHistory */ if(!$model->getUserId()) $model->setUserName(__('Anonymous', 'learndash')); else if($model->getUserName() == '') $model->setUserName(__('Deleted user', 'learndash')); $sum = $model->getCorrectCount() + $model->getIncorrectCount(); $result = round(100 * $model->getPoints() / $model->getGPoints(), 2).'%'; $model->setResult($result); $model->setFormatTime(WpProQuiz_Helper_Until::convertTime( $model->getCreateTime(), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Management_Display', 'statistics_time_format' ) //get_option('wpProQuiz_statisticTimeFormat', 'Y/m/d g:i A') )); $model->setFormatCorrect($model->getCorrectCount().' ('.round(100 * $model->getCorrectCount() / $sum, 2).'%)'); $model->setFormatIncorrect($model->getIncorrectCount().' ('.round(100 * $model->getIncorrectCount() / $sum, 2).'%)'); } $view = new WpProQuiz_View_StatisticsAjax(); $view->historyModel = $statisticModel; $html = $view->getHistoryTable(); $navi = null; if(isset($data['generateNav']) && $data['generateNav']) { $count = $statisticRefMapper->countHistory($quizId, $data['users'], $startTime, $endTime); $navi = ceil(($count > 0 ? $count : 1) / $limit); } return json_encode(array( 'html' => $html, 'navi' => $navi )); } public static function ajaxLoadStatisticUser($data, $func) { // The userId is not passed into this data payload. so for now we set to zero. We will load it via the $statisticRefMapper shortly after $userId = 0; // intval($data['userId']); if ( ( isset( $data['statistic_nonce'] ) ) && ( !empty( $data['statistic_nonce'] ) ) ) { if ( ( isset( $data['userId'] ) ) && ( !empty( $data['userId'] ) ) ) $userId = intval( $data['userId'] ); if ( !wp_verify_nonce( $data['statistic_nonce'], 'statistic_nonce_'. $data['refId'] .'_'. get_current_user_id() .'_'. $userId ) ) { return json_encode(array()); } } else if ( !current_user_can( 'wpProQuiz_show_statistics' ) ) { return json_encode(array()); } $quizId = $data['quizId']; $refId = $data['refId']; $avg = (bool)$data['avg']; $refIdUserId = $avg ? $userId : $refId; $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $statisticModel = $statisticRefMapper->fetchByRefId($refIdUserId, $quizId); if ( $statisticModel instanceof WpProQuiz_Model_StatisticRefModel ) { $userId = $statisticModel->getUserId(); } $statisticUserMapper = new WpProQuiz_Model_StatisticUserMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $statisticUsers = $statisticUserMapper->fetchUserStatistic($refIdUserId, $quizId, $avg); $output = array(); foreach($statisticUsers as $statistic) { if(!isset($output[$statistic->getCategoryId()])) { $output[$statistic->getCategoryId()] = array( 'questions' => array(), 'categoryId' => $statistic->getCategoryId(), 'categoryName' => $statistic->getCategoryId() ? $statistic->getCategoryName() : esc_html__('No category', 'learndash') ); } $o = &$output[$statistic->getCategoryId()]; $question_item = array( 'correct' => $statistic->getCorrectCount(), 'incorrect' => $statistic->getIncorrectCount(), 'hintCount' => $statistic->getHintCount(), 'time' => $statistic->getQuestionTime(), 'points' => $statistic->getPoints(), 'gPoints' => $statistic->getGPoints(), 'statistcAnswerData' => $statistic->getStatisticAnswerData(), 'questionName' => $statistic->getQuestionName(), 'questionAnswerData' => $statistic->getQuestionAnswerData(), 'answerType' => $statistic->getAnswerType(), 'questionId' => $statistic->getQuestionId() ); $questionId = $statistic->getQuestionId(); if ( !empty( $questionId ) ) { $questionMapper = new WpProQuiz_Model_QuestionMapper(); $question = $questionMapper->fetchById( intval( $questionId ) ); if ( ( !empty( $question ) ) && ( $question instanceof WpProQuiz_Model_Question ) ) { $question_item['questionCorrectMsg'] = $question->getCorrectMsg(); $question_item['questionIncorrectMsg'] = $question->getIncorrectMsg(); } } // For the sort_answer items. This worked correctly with LD 2.0.6.8. But in 2.1.x there was a change where // the stored value for 'statistcAnswerData' was not simply keys to match 'questionAnswerData' but md5 value. // This causes a mis-match when viewing statistics data. To complicate things we will have a mix of LD 2.0.6.8 // quiz values and 2.1.x quiz values. if (($question_item['answerType'] == 'sort_answer') || ($question_item['answerType'] == 'matrix_sort_answer')) { if ((isset($question_item['questionAnswerData'])) && (!empty($question_item['questionAnswerData'])) && (isset($question_item['statistcAnswerData'])) && (!empty($question_item['statistcAnswerData']))) { // So first we check the value of the first item from 'statistcAnswerData'. If the value // is a simple int then we can move on. If not, then we have some work to do. $statistcAnswerData_item = $question_item['statistcAnswerData'][0]; if (($statistcAnswerData_item == -1 ) || (strcmp($statistcAnswerData_item, intval($statistcAnswerData_item)) !== 0)) { $questionId = $statistic->getQuestionId(); // Next we loop over the 'questionAnswerData' items. foreach($question_item['questionAnswerData'] as $q_k => $q_v) { // Take the item key and encode it. //$datapos = LD_QuizPro::datapos($questionId, intval($q_k)); // We can't call LD_QuizPro::datapos because is uses current_user which will NOT match the statistic user. $datapos = md5( intval($userId) . $questionId . intval($q_k) ); // If we find that encoded value in the 'statistcAnswerData' we update the value. $s_pos = array_search($datapos, $question_item['statistcAnswerData'], true); if ($s_pos !== false) { $question_item['statistcAnswerData'][$s_pos] = intval($q_k); } } } } } $question_item['result'] = ''; // For essay type questions if the related post (graded_id) is still in the 'not_graded post_status we clear out the incorrect value. // The reason for this is within the statistics logic either the correct or incorrect field is set. In the case of not graded essays // the result is the incorrect field will be set to 1. See LEARNDASH-212 if ( $question_item['answerType'] == 'essay' ) { if ( ( isset( $question_item['statistcAnswerData']['graded_id'] ) ) && ( !empty( $question_item['statistcAnswerData']['graded_id'] ) ) ) { $graded_post = get_post( $question_item['statistcAnswerData']['graded_id'] ); if ( ( $graded_post ) && ( is_a( $graded_post, 'WP_Post') ) ) { $graded_data = learndash_get_submitted_essay_data( $data['quizId'], $question_item['questionId'], $graded_post ); if ( isset( $graded_data['status'] ) ) { if ( 'graded' === $graded_data['status'] ) { if ( isset( $graded_data['points_awarded'] ) ) { $question_item['correct'] = absint( $graded_data['points_awarded'] ); $question_item['points'] = absint( $graded_data['points_awarded'] ); $question_item['incorrect'] = absint( $question_item['gPoints'] ) - $question_item['correct']; $question_item['result'] = esc_html__( 'Graded', 'learndash' ); } } else { $question_item['result'] = esc_html__( 'Ungraded', 'learndash' ); } } } } } /** * Allow filter of the new 'Result' column output. This is pretty free-form and was not used prior to v2.4 * @since v2.4 */ $question_item['result'] = apply_filters( 'learndash-quiz-statistics-result', $question_item['result'], $question_item ); $o['questions'][] = $question_item; } $view = new WpProQuiz_View_StatisticsAjax(); $view->avg = $avg; $view->statisticModel = $statisticRefMapper->fetchByRefId($refIdUserId, $quizId, $avg); $view->userName = esc_html__('Anonymous', 'learndash'); if($view->statisticModel->getUserId()) { $userInfo = get_userdata($view->statisticModel->getUserId()); if($userInfo !== false) $view->userName = $userInfo->user_login.' ('.$userInfo->display_name.')'; else $view->userName = esc_html__('Deleted user', 'learndash'); } if(!$avg) { $view->forms = $formMapper->fetch($quizId); } $view->userStatistic = $output; $html = $view->getUserTable(); return json_encode(array( 'html' => $html )); } public static function ajaxRestStatistic($data, $func) { if(!current_user_can('wpProQuiz_reset_statistics')) { return; } $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); switch ($data['type']) { case 0: //RefId or UserId if($data['refId']) $statisticRefMapper->deleteByRefId($data['refId']); else if($data['userId'] != '') $statisticRefMapper->deleteByUserIdQuizId($data['userId'], $data['quizId']); break; case 1: //alles $statisticRefMapper->deleteAll($data['quizId']); break; } } public static function ajaxLoadStatsticOverviewNew($data, $func) { if(!current_user_can('wpProQuiz_show_statistics')) { return json_encode(array()); } $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $quizId = $data['quizId']; $page = (isset($data['page']) && $data['page'] > 0) ? $data['page'] : 1; $limit = $data['pageLimit']; $start = $limit * ($page - 1); $statisticModel = $statisticRefMapper->fetchStatisticOverview($quizId, $data['onlyCompleted'], $start, $limit); $view = new WpProQuiz_View_StatisticsAjax(); $view->statisticModel = $statisticModel; $navi = null; if(isset($data['generateNav']) && $data['generateNav']) { $count = $statisticRefMapper->countOverviewNew($quizId, $data['onlyCompleted']); $navi = ceil(($count > 0 ? $count : 1) / $limit); } return json_encode(array( 'navi' => $navi, 'html' => $view->getOverviewTable() )); } } lib/view/WpProQuiz_View_FrontToplist.php 0000666 00000002631 15214236625 0014452 0 ustar 00
|
|
|
|
"I {[play][love][hate]} soccer" . In this case answers play, love OR hate are correct.', 'learndash') ); ?>
getAnswer(), 'cloze', array('textarea_rows' => 10, 'textarea_name' => 'answerData[cloze][answer]')); ?>
*
*
getAnswer(), 'assessment', array('textarea_rows' => 10, 'textarea_name' => 'answerData[assessment][answer]')); ?>
| (hh:mm:ss) | ||||||||
|---|---|---|---|---|---|---|---|---|
| : categoryList[$k]->getCategoryName(); ?> | ||||||||
| getTitle(); ?> | getPoints(); ?> | |||||||
| getFieldname()); ?> | asdfffffffffffffffffffffsadfsdfa sf asd fas |
'.$msg.'
'.$msg.'
| 'ldAdvQuiz', 'module' => 'question', 'action' => 'addEdit', 'quiz_id' => $this->quiz->getId(), 'questionId' => $question->getId(), 'post_id' => @$_GET['post_id'] ), admin_url('admin.php') ); ?>getTitle(); ?> | getAnswerType(); if (isset($learndash_question_types[$question_type])) { echo $learndash_question_types[$question_type]; } ?> | getCategoryName(); ?> | getPoints(); ?> | |
| ID; ?> - ID ); ?> | ID, 'quiz_pro' ); $quiz_pro_id = absint( $quiz_pro_id ); if ( ! empty( $quiz_pro_id ) ) { $quiz_mapper = new WpProQuiz_Model_QuizMapper(); $quiz_pro = $quiz_mapper->fetch( $quiz_pro_id ); if ( ( is_a( $quiz_pro, 'WpProQuiz_Model_Quiz' ) ) && ( $quiz_pro_id === $quiz_pro->getId() ) ) { $valid_quiz_pro = true; echo $quiz_pro_id . ' - ' . esc_attr( $quiz_pro->getName() ); } } if ( false === $valid_quiz_pro ) { ?> | |
| '; echo esc_html( $form->getFieldname() ); echo $form->isRequired() ? '*' : ''; echo ''; ?> |
getType() ) {
case WpProQuiz_Model_Form::FORM_TYPE_TEXT:
case WpProQuiz_Model_Form::FORM_TYPE_EMAIL:
case WpProQuiz_Model_Form::FORM_TYPE_NUMBER:
echo 'isRequired() . '" data-type="' . $form->getType() . '" data-form_id="' . $form->getFormId() . '">';
break;
case WpProQuiz_Model_Form::FORM_TYPE_TEXTAREA:
echo '';
break;
case WpProQuiz_Model_Form::FORM_TYPE_CHECKBOX:
echo 'isRequired() . '" data-type="' . $form->getType() . '" data-form_id="' . $form->getFormId() . '">';
break;
case WpProQuiz_Model_Form::FORM_TYPE_DATE:
echo ' ';
echo WpProQuiz_Helper_Until::getDatePicker( get_option( 'date_format', 'j. F Y' ), $name );
echo ' ';
break;
case WpProQuiz_Model_Form::FORM_TYPE_RADIO:
echo '';
if ( $form->getData() !== null ) {
foreach ( $form->getData() as $data ) {
echo ' ';
}
}
echo ' ';
break;
case WpProQuiz_Model_Form::FORM_TYPE_SELECT:
if ( $form->getData() !== null ) {
echo '';
}
break;
case WpProQuiz_Model_Form::FORM_TYPE_YES_NO:
echo '';
echo ' ';
echo ' ';
echo ' ';
break;
}
if ( isset( $validateText[ $form->getType() ] ) ) {
echo '' . $validateText[ $form->getType() ] . ' ';
} else {
echo '' . esc_html__( 'You must fill out this field.', 'learndash' ) . ' ';
}
?>
|
'. print_r($user_quizzes, true) .''); if ( !empty( $user_quizzes ) ) { //krsort($user_quizzes); $user_quizzes = array_reverse($user_quizzes); //error_log('sorted: user_quizzes
'. print_r($user_quizzes, true) .''); foreach( $user_quizzes as $user_quiz_idx => $user_quiz ) { if ( ( isset( $user_quiz['quiz'] ) ) && ( $user_quiz['quiz'] == $post->ID ) ) { if ( ( isset( $user_quiz['pro_quizid'] ) ) && ( $user_quiz['pro_quizid'] == $this->quiz->getID() ) ) { if ( ( isset( $user_quiz['statistic_ref_id'] ) ) && ( !empty($user_quiz['statistic_ref_id']) ) ) { //error_log('found idx['. $user_quiz_idx .']'); ?>
|
|
|
|
|
|
|
captchaIsInstalled) { ?>
|
|
|
|
|
|
|
|
|
|
| continue', 'learndash'); ?> | |||
|---|---|---|---|
|
|
|
|
|
|
email['from'] ) ) && ( !is_email( $this->email['from'] ) ) ) {
?>
(%s) will be used.', 'learndash') ), get_option('admin_email') ); ?> |
|
email['message'], 'adminEmailEditor', array('textarea_rows' => 20, 'textarea_name' => 'email[message]'));
?>
:
|
| getUserName(); ?> | getFormatTime(); ?> | getFormatCorrect(); ?> | getFormatIncorrect(); ?> | getPoints(); ?> | getResult(); ?>% |
|---|---|---|---|---|---|
|
|
| getFieldname()); ?> | getType()) { case WpProQuiz_Model_Form::FORM_TYPE_TEXT: case WpProQuiz_Model_Form::FORM_TYPE_TEXTAREA: case WpProQuiz_Model_Form::FORM_TYPE_EMAIL: case WpProQuiz_Model_Form::FORM_TYPE_NUMBER: case WpProQuiz_Model_Form::FORM_TYPE_RADIO: case WpProQuiz_Model_Form::FORM_TYPE_SELECT: echo esc_html($str); break; case WpProQuiz_Model_Form::FORM_TYPE_CHECKBOX: echo $str == '1' ? esc_html__('ticked', 'learndash') : esc_html__('not ticked', 'learndash'); break; case WpProQuiz_Model_Form::FORM_TYPE_YES_NO: echo $str == 1 ? esc_html__('Yes', 'learndash') : esc_html__('No', 'learndash'); break; case WpProQuiz_Model_Form::FORM_TYPE_DATE: echo date_format(date_create($str), get_option('date_format')); break; } ?> |
| (hh:mm:ss) | ||||||
|---|---|---|---|---|---|---|
| getUserName()); ?> getUserName()); } ?> | ||||||