<?php

// require library
require_once '../autoload.php';
// initialization
$se = new SphereEngine\Api("access_token", "v3", "endpoint");
$client = $se->getCompilersClient();
Пример #2
0
 public function sphereGetCompilers()
 {
     $seCompilersApi = new SphereEngine\Api("02994435062fb95b5f3e6938e5aa433e", "v3", "languages");
     //new SphereEngine\Api($TOKEN, "v3", "languages");
     $seCompilersClient = $seCompilersApi->getCompilersClient();
     $serverOutput = $seCompilersClient->compilers();
     $this->sphereSaveCompilers($serverOutput);
     return $serverOutput;
 }
Пример #3
0
<?php

require_once './autoload.php';
$se_compilers = new SphereEngine\Api("access_token", "v3", "endpoint");
$compilersClient = $se_compilers->getCompilersClient();
$se_problems = new SphereEngine\Api("access_token", "v3", "endpoint");
$problemsClient = $se_problems->getProblemsClient();
$compilers_unit_tests = ['wrong access token' => function ($not_used) {
    $client = (new SphereEngine\Api("fake_access_token", "v3", "endpoint"))->getCompilersClient();
    try {
        $client->test();
        return 0;
    } catch (SphereEngine\SphereEngineResponseException $e) {
        if ($e->getCode() == 401) {
            return 1;
        }
        return 0;
    }
}, 'test' => function ($client) {
    return $client->test()['pi'] == 3.14;
}, 'compilers' => function ($client) {
    return $client->compilers()[11][0] == 'C';
}, 'submissions get existing' => function ($client) {
    return $client->submissions->get(38436074)['result'] == 15;
}, 'submissions get non existing' => function ($client) {
    try {
        $r = $client->submissions->get(9999999999);
        return 0;
    } catch (SphereEngine\SphereEngineResponseException $e) {
        if ($e->getCode() == 404) {
            return 1;
 /**
  * Define this form - called by the parent constructor
  */
 public function definition()
 {
     $mform = $this->_form;
     list($sepl, $data) = $this->_customdata;
     $sepl->add_submission_form_elements($mform, $data);
     /*
     
     $ch = curl_init();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "http://api.compilers.sphere-engine.com/api/v3/languages?access_token=02994435062fb95b5f3e6938e5aa433e");
     curl_setopt($ch, CURLOPT_POST, 1);
     #curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
     // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $server_output = curl_exec ($ch);*/
     #var_dump($result);
     $client = (new SphereEngine\Api("02994435062fb95b5f3e6938e5aa433e", "v3", "languages"))->getProblemsClient();
     $se_compilers = new SphereEngine\Api("02994435062fb95b5f3e6938e5aa433e", "v3", "languages");
     $compilersClient = $se_compilers->getCompilersClient();
     $server_output = $compilersClient->compilers();
     # $result = json_decode($server_output, true);
     #  $jsonString = json_decode($server_output, true);
     #curl_close ($ch);
     #var_dump($jsonString);
     $mform->addElement('select', 'compiler', 'Compiler: ', $server_output);
     //, $state);
     $this->add_action_buttons(false, 'Refresh');
     #$mform->addElement('select', 'compiler', 'Compiler: ',$server_output);//, $state);
     $this->add_action_buttons(true, get_string('savechanges', 'sepl'));
     if ($data) {
         # 	$compiler = $mform->g
         #var_dump($data);
         $ii = 0;
         foreach ($data as $tes) {
             $ii = 0;
             foreach ($tes as $tes2) {
                 var_dump($tes2);
                 if ($ii == 0) {
                     $textToSend = $tes2;
                 }
                 //text from online editor - ugly way but it works...
                 $ii++;
             }
         }
         $myToken = "02994435062fb95b5f3e6938e5aa433e";
         $client = (new SphereEngine\Api($myToken, "v3", "endpoint"))->getCompilersClient();
         $res = $client->submissions->create("UT1952", $textToSend, 11);
         $selectedItem =& $mform->getElement('compiler')->getSelected();
         var_dump($selectedItem);
         #var_dump($mform->get_data('compiler'));
         /*
         *  example of saving record in moodle db
         * $newrecord = new stdClass();
         $newrecord->name = $data->dname;
         $newrecord->id = $DB->insert_record('tbl_name', $newrecord);
         * 
         */
         $mform->addElement('text', 'sphereReturn', $res, $attributes);
         var_dump($res);
         $this->set_data($data);
     }
 }