Refactoring the editor code
This commit is contained in:
		@@ -25,12 +25,12 @@
 | 
				
			|||||||
require_once(__DIR__ . "/../../config.php");
 | 
					require_once(__DIR__ . "/../../config.php");
 | 
				
			||||||
require_once(__DIR__ . "/classes/forms.php");
 | 
					require_once(__DIR__ . "/classes/forms.php");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$idservice = optional_param("idservice", 0, PARAM_INT);
 | 
					$serviceid = optional_param("serviceid", 0, PARAM_INT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require_login();
 | 
					require_login();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Link generation */
 | 
					/* Link generation */
 | 
				
			||||||
$urlparameters = array("idservice" => $idservice);
 | 
					$urlparameters = array("serviceid" => $serviceid);
 | 
				
			||||||
$managerservice = new moodle_url("/local/webhooks/managerservice.php", $urlparameters);
 | 
					$managerservice = new moodle_url("/local/webhooks/managerservice.php", $urlparameters);
 | 
				
			||||||
$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters);
 | 
					$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters);
 | 
				
			||||||
$PAGE->set_url($baseurl, $urlparameters);
 | 
					$PAGE->set_url($baseurl, $urlparameters);
 | 
				
			||||||
@@ -52,26 +52,25 @@ if ($mform->is_cancelled()) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Getting the data */
 | 
					/* Getting the data */
 | 
				
			||||||
if ($idediting = boolval($idservice)) {
 | 
					if ($idediting = boolval($serviceid)) {
 | 
				
			||||||
    $servicerecord = $DB->get_record("local_webhooks_service", array("id" => $idservice), "*", MUST_EXIST);
 | 
					    $servicerecord = $DB->get_record("local_webhooks_service", array("id" => $serviceid), "*", MUST_EXIST);
 | 
				
			||||||
    $mform->set_data($servicerecord);
 | 
					    $mform->set_data($servicerecord);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Processing of received data */
 | 
					/* Processing of received data */
 | 
				
			||||||
if ($data = $mform->get_data()) {
 | 
					if ($data = $mform->get_data()) {
 | 
				
			||||||
    /* Packing of data */
 | 
					 | 
				
			||||||
    if (!empty($data->events)) {
 | 
					    if (!empty($data->events)) {
 | 
				
			||||||
        $data->events = base64_encode(gzcompress(serialize($data->events), 9));
 | 
					        $data->events = base64_encode(gzcompress(serialize($data->events), 9));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ($idediting) {
 | 
					    if (boolval($idediting)) {
 | 
				
			||||||
        $data->id = $idservice;
 | 
					        $data->id = $serviceid;
 | 
				
			||||||
        $DB->update_record("local_webhooks_service", $data);
 | 
					        $DB->update_record("local_webhooks_service", $data);
 | 
				
			||||||
 | 
					        redirect($managerservice, new lang_string("eventwebserviceserviceupdated", "webservice"));
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        $DB->insert_record("local_webhooks_service", $data);
 | 
					        $DB->insert_record("local_webhooks_service", $data);
 | 
				
			||||||
 | 
					        redirect($managerservice, new lang_string("eventwebserviceservicecreated", "webservice"));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    redirect($managerservice);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Page template */
 | 
					/* Page template */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user