public function findClasses($class)
 {
     try {
         $queryObject = array('queryObject' => json_encode(array('coursesection_title' => $class->getTitle(), 'date_from' => $class->getDateFrom(), 'integration_id' => $class->getIntegrationId(), 'user_id' => $class->getUserId(), 'user_role' => $class->getUserRole())));
         $soap = $this->discoverCourseSectionIds($queryObject);
         $response = new Response($this);
         if ($response->getStatus() == 'error') {
             throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription(), parent::getLogPath());
         } else {
             $tiiClass = new TiiClass();
             $classids = array();
             if (isset($soap->sourcedIdSet->sourcedId)) {
                 if (!is_array($soap->sourcedIdSet->sourcedId)) {
                     $soap->sourcedIdSet->sourcedId = array($soap->sourcedIdSet->sourcedId);
                 }
                 foreach ($soap->sourcedIdSet->sourcedId as $id) {
                     $classids[] = $id;
                 }
             }
             $tiiClass->setClassIds($classids);
             $response->setClass($tiiClass);
         }
         return $response;
     } catch (SoapFault $e) {
         throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath());
     }
 }
예제 #2
0
/**
 * Gets the courses for this account from Turnitin.
 *
 * @param array $tiiintegrationids the integration ids we want courses from
 * @return array of data in a datatables readable format
 */
function turnitintooltwo_get_courses_from_tii($tiiintegrationids, $coursetitle, $courseintegration, $courseenddate = null, $requestsource = "mod")
{
    global $CFG, $DB, $OUTPUT, $USER;
    set_time_limit(0);
    $_SESSION["stored_tii_courses"] = array();
    $return = array();
    $return["aaData"] = array();
    $secho = optional_param('sEcho', 0, PARAM_INT);
    $ssortdir = optional_param('sSortDir_0', 'desc', PARAM_ALPHA);
    $isortcol = optional_param('iSortCol_0', '6', PARAM_INT);
    $turnitincomms = new turnitintooltwo_comms();
    $turnitincall = $turnitincomms->initialise_api();
    $class = new TiiClass();
    $class->setTitle($coursetitle);
    if ($courseenddate != null) {
        $class->setDateFrom(gmdate("Y-m-d", strtotime($courseenddate)) . 'T00:00:00Z');
    }
    if (array_key_exists($courseintegration, $tiiintegrationids)) {
        $class->setIntegrationId($courseintegration);
    }
    if (!is_siteadmin()) {
        $turnitintooltwouser = new turnitintooltwo_user($USER->id, 'Instructor');
        $tiiinstructorid = $turnitintooltwouser->tii_user_id;
        $class->setUserId($tiiinstructorid);
        $class->setUserRole('Instructor');
    }
    try {
        $response = $turnitincall->findClasses($class);
        $findclass = $response->getClass();
        $classids = $findclass->getClassIds();
    } catch (Exception $e) {
        turnitintooltwo_activitylog(get_string('migrationcoursegeterror', 'turnitintooltwo'), "REQUEST");
        $classids = array();
    }
    // Get currently linked courses.
    $currentcourses = array();
    if (!empty($classids)) {
        list($insql, $inparams) = $DB->get_in_or_equal($classids);
        $currentcourses["PP"] = $DB->get_records_sql("SELECT tc.turnitin_cid FROM {turnitintooltwo_courses} tc " . "RIGHT JOIN {course} c ON c.id = tc.courseid " . "WHERE tc.course_type = 'PP' AND tc.turnitin_cid " . $insql, $inparams);
        $currentcourses["TT"] = $DB->get_records_sql("SELECT tc.turnitin_cid FROM {turnitintooltwo_courses} tc " . "RIGHT JOIN {course} c ON c.id = tc.courseid " . "WHERE tc.course_type = 'TT' AND tc.turnitin_cid " . $insql, $inparams);
    }
    $class = new TiiClass();
    $class->setClassIds($classids);
    $tiicourses = array();
    $i = 0;
    if (!empty($classids)) {
        try {
            $response = $turnitincall->readClasses($class);
            $readclasses = $response->getClasses();
            foreach ($readclasses as $readclass) {
                if (array_key_exists($readclass->getIntegrationId(), $tiiintegrationids)) {
                    $_SESSION["stored_tii_courses"][$readclass->getClassId()] = $readclass->getTitle();
                    // If we're coming from block we don't need any information, just the number of records
                    if ($requestsource == "mod") {
                        $linkpage = is_siteadmin() ? "settings_extras.php" : "extras.php";
                        $titlecell = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/' . $linkpage . '?cmd=class_recreation&id=' . $readclass->getClassId() . '&view_context=box&sesskey=' . sesskey(), $readclass->getTitle(), array("class" => "course_recreate", "id" => "course_" . $readclass->getClassId()));
                        $datecell = html_writer::link('.edit_course_end_date_form', html_writer::tag('span', userdate(strtotime($readclass->getEndDate()), get_string('strftimedate', 'langconfig')), array("id" => $readclass->getClassId() . "_" . gmdate("j", strtotime($readclass->getEndDate())) . "_" . gmdate("n", strtotime($readclass->getEndDate())) . "_" . gmdate("Y", strtotime($readclass->getEndDate())))) . " " . $OUTPUT->pix_icon('edit', get_string('edit'), 'mod_turnitintooltwo'), array("class" => "edit_course_end_link", "id" => "course_date_" . $readclass->getClassId()));
                        $checkbox = '';
                        $class = '';
                        if (empty($currentcourses["PP"][$readclass->getClassId()]) && empty($currentcourses["TT"][$readclass->getClassId()])) {
                            $class = 'hidden_class';
                            $checkbox = html_writer::checkbox('check_' . $readclass->getClassId(), $readclass->getClassId(), false, '', array("class" => "browser_checkbox"));
                        }
                        $moodlecell = $OUTPUT->pix_icon('tick', get_string('moodlelinked', 'turnitintooltwo'), 'mod_turnitintooltwo', array('class' => $class, 'id' => 'tick_' . $readclass->getClassId()));
                        $tiicourses[$i] = array($checkbox, $titlecell, $tiiintegrationids[$readclass->getIntegrationId()], $datecell, $readclass->getClassId(), $moodlecell, $readclass->getTitle(), userdate(strtotime($readclass->getEndDate()), get_string('strftimedate', 'langconfig')));
                    }
                    $i++;
                    // Keep course names in case of course recreation.
                    $_SESSION['tii_classes'][$readclass->getClassId()] = $readclass->getTitle();
                }
            }
            if (count($tiicourses) > 0 && $requestsource == "mod") {
                turnitintooltwo_sort_array($tiicourses, $isortcol, $ssortdir);
                $j = 0;
                foreach ($tiicourses as $class) {
                    $return["aaData"][$j] = $class;
                    $j++;
                }
            }
        } catch (Exception $e) {
            $turnitincomms->handle_exceptions($e, 'coursegettiierror');
        }
    }
    $return["iTotalRecords"] = $i;
    $return["iTotalDisplayRecords"] = $i;
    $return["sEcho"] = $secho;
    $return["blockHTML"] = $i == 0 ? '' : get_string('coursestomigrate', 'mod_turnitintooltwo', $i);
    return $return;
}