/**
  * Constructor
  *
  * @param \stdClass $collaborate
  * @param \cm_info $cm
  * @param \context_module $context;
  * @param \stdClass $user;
  * @throws \coding_exception
  * @throws \require_login_exception
  */
 public function __construct(\stdClass $collaborate, \cm_info $cm, \context_module $context, \stdClass $user)
 {
     global $DB;
     $this->collaborate = $collaborate;
     $this->course = $cm->get_course();
     $this->cm = $cm;
     $this->id = $cm->instance;
     $this->context = $context;
     $this->user = $user;
     $this->collaborate = $DB->get_record('collaborate', array('id' => $this->id), '*', MUST_EXIST);
     $this->api = api::get_api();
 }
예제 #2
0
 /**
  * get recordings
  *
  * @param int | object $collaborate
  * @return array
  */
 public static function get_recordings($collaborate)
 {
     global $DB;
     if (!is_object($collaborate)) {
         $collaborate = $DB->get_record('collaborate', array('id' => $collaborate));
     }
     $config = get_config('collaborate');
     $api = api::get_api();
     $session = new HtmlSessionRecording();
     $session->setSessionId($collaborate->sessionid);
     $result = $api->ListHtmlSessionRecording($session);
     if (!$result) {
         return [];
     }
     $respobjs = $result->getHtmlSessionRecordingResponse();
     if (!is_array($respobjs) || empty($respobjs)) {
         return [];
     }
     return $respobjs;
 }
예제 #3
0
/**
 * Removes an instance of the collaborate from the database
 *
 * Given an ID of an instance of this module,
 * this function will permanently delete the instance
 * and any data that depends on it.
 *
 * @param int $id Id of the module instance
 * @return boolean Success/Failure
 */
function collaborate_delete_instance($id)
{
    global $DB;
    if (!($collaborate = $DB->get_record('collaborate', array('id' => $id)))) {
        return false;
    }
    // API request deletion.
    $api = api::get_api();
    $api->set_silent(true);
    $params = new RemoveHtmlSession($collaborate->sessionid);
    try {
        $result = $api->RemoveHtmlSession($params);
    } catch (Exception $e) {
        $result = false;
    }
    if ($result === null) {
        // TODO: Warning - this is a bodge fix! - the wsdl2phpgenerator has set up this class so that it is expecting
        // a Success Response object but we are actually getting back a RemoveSessionSuccessResponse element in the
        // xml and as a result of that we end up with a 'null' object.
        $xml = $api->__getLastResponse();
        if (preg_match('/<success[^>]*>true<\\/success>/', $xml)) {
            // Manually create the response object!
            $result = new SuccessResponse(true);
        } else {
            $result = false;
        }
    }
    if (!$result || !$result->getSuccess()) {
        $api->process_error('error:failedtodeletesession', constants::SEV_WARNING);
    }
    // Delete main record.
    $DB->delete_records('collaborate', array('id' => $collaborate->id));
    collaborate_grade_item_delete($collaborate);
    return true;
}