function get_quiz($post)
 {
     require_once __DIR__ . "/../../API/Psr4AutoloaderClass.php";
     $loader = new Psr4AutoloaderClass();
     $loader->register();
     $loader->addNamespace('InstructureCanvasAPI', __DIR__ . "/../../API/InstructureCanvasAPI/src");
     $API = new InstructureCanvasAPI\InstructureCanvasAPI(array("site" => get_post_meta($post->ID, "courseURL", true), "token" => get_post_meta($post->ID, "courseToken", true), "webService" => "CURL"));
     $quizzes = new InstructureCanvasAPI\Courses\Quizzes\Quizzes();
     $quizzes->setAPI($API);
     $quizzes->setCourseID(get_post_meta($post->ID, "courseID", true));
     $data = $quizzes->getQuiz($_POST['item']);
     $quizzes = $data->content;
     $loader->unregister();
     return $quizzes;
 }
Exemple #2
0
    function quiz()
    {
        if (isset($_POST['molie-quiz-nonce'])) {
            if (wp_verify_nonce($_POST['molie-quiz-nonce'], "molie-quiz-nonce")) {
                $course_id = get_post_meta($_POST['course_id'], "courseID", true);
                $course_token = get_post_meta($_POST['course_id'], "courseToken", true);
                $course_url = get_post_meta($_POST['course_id'], "courseURL", true);
                require_once __DIR__ . "/../../API/Psr4AutoloaderClass.php";
                $loader = new Psr4AutoloaderClass();
                $loader->register();
                $loader->addNamespace('InstructureCanvasAPI', __DIR__ . "/../../API/InstructureCanvasAPI/src");
                $API = new InstructureCanvasAPI\InstructureCanvasAPI(array("site" => $course_url, "token" => $course_token, "webService" => "CURL"));
                $quizzes = new InstructureCanvasAPI\Courses\Quizzes\Quizzes();
                $quizzes->setAPI($API);
                $quizzes->setCourseID($course_id);
                $data = $quizzes->getquizzes();
                if ($data) {
                    if (count($data->content) != 0) {
                        echo "<div id='molie_choose'>";
                        echo "<h2>" . __("quizzes in this course") . "</h2>";
                        echo "<div id='importProgress'><p><strong>" . __("Import Progress") . " <span id='importTotal'></span></strong></p><div id='importProgressBar'></div></div>";
                        echo '<form id="molie_choose_form" action="javascript:function connect(){return false;};">';
                        echo "<input type='submit' id='molie_quiz_submit' value='" . __("Link quizzes") . "' />";
                        echo "<input type='submit' id='molie_quiz_skip' value='" . __("Skip step") . "' />";
                        echo "<p><span><a href='javascript:molie_select_all()'>" . __("Select All") . "</a></span> <span><a href='javascript:molie_unselect_all()'>" . __("Unselect All") . "</a></span></p>";
                        echo "<ul>";
                        foreach ($data->content as $quiz) {
                            echo "<li>";
                            if (get_post_meta($_POST['course_id'], "canvasQuiz_" . $quiz->id, true) != "") {
                                $link_checked = "";
                                $link_info = __("quiz already linked");
                            } else {
                                $link_checked = "checked";
                                $link_info = "";
                            }
                            echo "<input type='checkbox' " . $link_checked . " id='" . $quiz->id . "' course_post='" . $_POST['course_id'] . "'>" . $quiz->title . "<span id='update" . $quiz->id . "'>" . $link_info . "</span></li>";
                        }
                        echo "</ul>";
                        echo "<input type='submit' id='molie_quiz_submit' value='" . __("Link quizzes") . "' />";
                        echo "</form>";
                        echo "</div>";
                        echo "<div id='molie_quiz_assignments' style='display:none'>";
                        echo '<form method="post" action="' . admin_url("admin.php?page=molie_assignments") . '">';
                        echo "<input name='course_id' type='hidden' value='" . $_POST['course_id'] . "' />";
                        echo wp_nonce_field("molie-assignment-nonce", "molie-assignment-nonce");
                        echo "<input type='submit' value='" . __("Now, Assignments") . "' />";
                        echo "</form>";
                        echo "</div>";
                    }
                }
                $loader->unregister();
            } else {
            }
        } else {
            $args = array("post_type" => "linkedcanvascourse", "post_status" => "publish");
            $courses = get_posts($args);
            if (count($courses) != 0) {
                echo "<h2>" . __("Choose a course") . "</h2>";
                $nonce = wp_create_nonce("molie-quiz-nonce");
                foreach ($courses as $course) {
                    ?>
						<form method="post" action='<?php 
                    echo admin_url("admin.php?page=molie_quiz");
                    ?>
'>
							<p><?php 
                    echo $course->post_title;
                    ?>
</p>
							<input type="hidden" name="molie-quiz-nonce" value="<?php 
                    echo $nonce;
                    ?>
"/>
							<input type="hidden" name="url" value="<?php 
                    echo get_post_meta($course->ID, "courseURL", true);
                    ?>
" />
							<input type="hidden" name="token" value="<?php 
                    echo get_post_meta($course->ID, "courseToken", true);
                    ?>
" />
							<input name="course_id" type="hidden" value="<?php 
                    echo $course->ID;
                    ?>
" />
							<input type="submit" value="<?php 
                    echo __("Get Quizzes");
                    ?>
" />
						</form>
					<?php 
                }
            }
        }
    }
 function check_quizzes()
 {
     if (wp_verify_nonce($_POST['nonce'], "molie_admin_check")) {
         require_once __DIR__ . "/../../API/Psr4AutoloaderClass.php";
         $loader = new Psr4AutoloaderClass();
         $loader->register();
         $loader->addNamespace('InstructureCanvasAPI', __DIR__ . "/../../API/InstructureCanvasAPI/src");
         $API = new InstructureCanvasAPI\InstructureCanvasAPI(array("site" => get_post_meta($_POST['course'], "courseURL", true), "token" => get_post_meta($_POST['course'], "courseToken", true), "webService" => "CURL"));
         $course_id = get_post_meta($_POST['course'], "courseID", true);
         $quizzes = new InstructureCanvasAPI\Courses\Quizzes\Quizzes();
         $quizzes->setAPI($API);
         $quizzes->setCourseID($course_id);
         $data = $quizzes->getquizzes();
         $diff = false;
         $quiz_diff = array();
         foreach ($data->content as $item) {
             global $wpdb;
             $data = $wpdb->get_results("select post_id from " . $wpdb->prefix . "postmeta where meta_key ='canvasQuizURL' and meta_value like '%" . $item->html_url . "%'");
             if (count($data) == 0) {
                 $diff = true;
                 array_push($quiz_diff, $item);
             }
         }
         if ($diff) {
             echo json_encode(array($diff, $quiz_diff));
         } else {
             echo json_encode(array($diff, $quiz_diff));
         }
     } else {
         echo "Nonce failed";
     }
     wp_die();
 }