/** * Set the number of user messages and any instructor rubrics from Turnitin */ public function set_user_values_from_tii() { $turnitincomms = new turnitintooltwo_comms(); $turnitincall = $turnitincomms->initialise_api(); $user = new TiiUser(); $user->setUserId($this->tii_user_id); try { $response = $turnitincall->readUser($user); $readuser = $response->getUser(); $this->usermessages = $readuser->getUserMessages(); $this->save_instructor_rubrics($readuser->getInstructorRubrics()); $tiiuser = array("id" => $readuser->getUserId(), "firstname" => $readuser->getFirstName(), "lastname" => $readuser->getLastName(), "email" => $readuser->getEmail()); return $tiiuser; } catch (Exception $e) { try { // We need to join the user to the account, we can only do that by adding the user to a class // make one and add them, then delete it. Awful workaround but should be rare. $class = new TiiClass(); $uuid = uniqid(microtime() . '-'); $class->setTitle($uuid); $response = $turnitincall->createClass($class); $newclass = $response->getClass(); $tiiclassid = $newclass->getClassId(); $membership = new TiiMembership(); $membership->setRole($this->role); $membership->setUserId($this->tii_user_id); $membership->setClassId($tiiclassid); $response = $turnitincall->createMembership($membership); $class->setClassId($tiiclassid); $response = $turnitincall->deleteClass($class); $response = $turnitincall->readUser($user); $readuser = $response->getUser(); $this->usermessages = $readuser->getUserMessages(); $this->save_instructor_rubrics($readuser->getInstructorRubrics()); } catch (Exception $e) { $turnitincomms->handle_exceptions($e, 'tiiusergeterror'); } } }
/** * Edit the course end date in Turnitin * * @global type $DB * @param int $tiicourseid The course id on Turnitin * @param int $tiicoursetitle The course title on Turnitin * @param date $courseenddate The new course end date to be set on Turnitin */ public static function edit_tii_course_end_date($tiicourseid, $tiicoursetitle, $courseenddate) { global $DB; $turnitincomms = new turnitintooltwo_comms(); $turnitincall = $turnitincomms->initialise_api(); $class = new TiiClass(); $class->setTitle($tiicoursetitle); $class->setClassId($tiicourseid); $class->setEndDate(gmdate("Y-m-d\\TH:i:s\\Z", $courseenddate)); try { $turnitincall->updateClass($class); return true; } catch (Exception $e) { $turnitincomms->handle_exceptions($e, 'classupdateerror'); } }
public function readClasses($class) { try { $soap = $this->readCourseSections(array('sourcedIdSet' => array('sourcedId' => $class->getClassIds()))); $response = new Response($this); if ($response->getStatus() == 'error') { throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription(), parent::getLogPath()); } else { $classes = array(); if (isset($soap->courseSectionRecordSet->courseSectionRecord)) { if (!is_array($soap->courseSectionRecordSet->courseSectionRecord)) { $soap->courseSectionRecordSet->courseSectionRecord = array($soap->courseSectionRecordSet->courseSectionRecord); } foreach ($soap->courseSectionRecordSet->courseSectionRecord as $record) { $tiiClass = new TiiClass(); $tiiClass->setClassId($record->sourcedGUID->sourcedId); $tiiClass->setTitle($record->courseSection->title->textString); $tiiClass->setEndDate($record->courseSection->timeFrame->end); foreach ($record->courseSection->extension->extensionField as $field) { $name = $field->fieldName; $method = 'set' . $name; if (is_callable(array($tiiClass, $method))) { $tiiClass->{$method}($field->fieldValue); } } $classes[] = $tiiClass; } } $response->setClasses($classes); } return $response; } catch (SoapFault $e) { throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath()); } }
case "test_connection": if (!confirm_sesskey()) { throw new moodle_exception('invalidsesskey', 'error'); } $data = array("connection_status" => "fail", "msg" => get_string('connecttestcommerror', 'turnitintooltwo')); if (is_siteadmin()) { // Initialise API connection. $account_id = required_param('account_id', PARAM_RAW); $account_shared = required_param('account_shared', PARAM_RAW); $url = required_param('url', PARAM_RAW); $turnitincomms = new turnitintooltwo_comms($account_id, $account_shared, $url); $istestingconnection = true; // Provided by Androgogic to override offline mode for testing connection. $tiiapi = $turnitincomms->initialise_api($istestingconnection); $class = new TiiClass(); $class->setTitle('Test finding a class to see if connection works'); try { $response = $tiiapi->findClasses($class); $data["connection_status"] = "success"; $data["msg"] = get_string('connecttestsuccess', 'turnitintooltwo'); } catch (Exception $e) { $turnitincomms->handle_exceptions($e, 'connecttesterror', false); } } echo json_encode($data); break; case "submit_nothing": if (!confirm_sesskey()) { throw new moodle_exception('invalidsesskey', 'error'); } $assignmentid = required_param('assignment', PARAM_INT);
/** * 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; }
/** * Test whether we can connect to Turnitin. * * Initially only being used if a student is logged in before checking whether they have accepted the EULA. */ public function test_turnitin_connection($workflowcontext = 'site') { $turnitincomms = new turnitin_comms(); $tiiapi = $turnitincomms->initialise_api(); $class = new TiiClass(); $class->setTitle('Test finding a class to see if connection works'); try { $response = $tiiapi->findClasses($class); return true; } catch (Exception $e) { $turnitincomms->handle_exceptions($e, 'connecttesterror', false); if ($workflowcontext == 'cron') { mtrace(get_string('ppeventsfailedconnection', 'plagiarism_turnitin')); } return false; } }
/** * Test whether we can connect to Turnitin. * * Initially only being used if a student is logged in before checking whether they have accepted the EULA. */ public function test_turnitin_connection() { $turnitincomms = new turnitin_comms(); $tiiapi = $turnitincomms->initialise_api(); $class = new TiiClass(); $class->setTitle('Test finding a class to see if connection works'); try { $response = $tiiapi->findClasses($class); return true; } catch (Exception $e) { $turnitincomms->handle_exceptions($e, 'connecttesterror', false); return false; } }