Moodle style fixes
Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
parent
99c835a63d
commit
d8f5be6670
@ -36,10 +36,10 @@ require_once($CFG->libdir . '/formslib.php');
|
|||||||
*/
|
*/
|
||||||
class local_webhooks_service_edit_form extends moodleform {
|
class local_webhooks_service_edit_form extends moodleform {
|
||||||
/**
|
/**
|
||||||
* @param string $base_url
|
* @param string $baseurl
|
||||||
*/
|
*/
|
||||||
public function __construct($base_url) {
|
public function __construct($baseurl) {
|
||||||
parent::__construct($base_url);
|
parent::__construct($baseurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,55 +48,55 @@ class local_webhooks_service_edit_form extends moodleform {
|
|||||||
* @throws \coding_exception
|
* @throws \coding_exception
|
||||||
*/
|
*/
|
||||||
protected function definition() {
|
protected function definition() {
|
||||||
$m_form =& $this->_form;
|
$mform =& $this->_form;
|
||||||
$size = array('size' => 60);
|
$size = array('size' => 60);
|
||||||
|
|
||||||
/* Form heading */
|
/* Form heading */
|
||||||
$m_form->addElement('header', 'edit-service-header-main', new lang_string('service', 'webservice'));
|
$mform->addElement('header', 'edit-service-header-main', new lang_string('service', 'webservice'));
|
||||||
|
|
||||||
/* Name of the service */
|
/* Name of the service */
|
||||||
$m_form->addElement('text', 'name', new lang_string('name', 'moodle'), $size);
|
$mform->addElement('text', 'name', new lang_string('name', 'moodle'), $size);
|
||||||
$m_form->addRule('name', null, 'required');
|
$mform->addRule('name', null, 'required');
|
||||||
$m_form->setType('name', PARAM_RAW);
|
$mform->setType('name', PARAM_RAW);
|
||||||
|
|
||||||
/* Callback address */
|
/* Callback address */
|
||||||
$m_form->addElement('text', 'point', new lang_string('url', 'moodle'), $size);
|
$mform->addElement('text', 'point', new lang_string('url', 'moodle'), $size);
|
||||||
$m_form->addRule('point', null, 'required');
|
$mform->addRule('point', null, 'required');
|
||||||
$m_form->setType('point', PARAM_URL);
|
$mform->setType('point', PARAM_URL);
|
||||||
|
|
||||||
/* Enabling the service */
|
/* Enabling the service */
|
||||||
$m_form->addElement('advcheckbox', 'status', new lang_string('enable', 'moodle'));
|
$mform->addElement('advcheckbox', 'status', new lang_string('enable', 'moodle'));
|
||||||
$m_form->setType('status', PARAM_BOOL);
|
$mform->setType('status', PARAM_BOOL);
|
||||||
$m_form->setDefault('status', 1);
|
$mform->setDefault('status', 1);
|
||||||
$m_form->setAdvanced('status');
|
$mform->setAdvanced('status');
|
||||||
|
|
||||||
/* Token */
|
/* Token */
|
||||||
$m_form->addElement('text', 'token', new lang_string('token', 'webservice'), $size);
|
$mform->addElement('text', 'token', new lang_string('token', 'webservice'), $size);
|
||||||
$m_form->addRule('token', null, 'required');
|
$mform->addRule('token', null, 'required');
|
||||||
$m_form->setType('token', PARAM_RAW);
|
$mform->setType('token', PARAM_RAW);
|
||||||
|
|
||||||
/* Content type */
|
/* Content type */
|
||||||
$content_type = array(
|
$contenttype = array(
|
||||||
'application/json' => 'application/json',
|
'application/json' => 'application/json',
|
||||||
'application/x-www-form-urlencoded' => 'application/x-www-form-urlencoded',
|
'application/x-www-form-urlencoded' => 'application/x-www-form-urlencoded',
|
||||||
);
|
);
|
||||||
|
|
||||||
$m_form->addElement('select', 'header', 'Content-Type', $content_type);
|
$mform->addElement('select', 'header', 'Content-Type', $contenttype);
|
||||||
$m_form->setAdvanced('header');
|
$mform->setAdvanced('header');
|
||||||
|
|
||||||
/* Form heading */
|
/* Form heading */
|
||||||
$m_form->addElement('header', 'edit-service-header-event', new lang_string('edulevel', 'moodle'));
|
$mform->addElement('header', 'edit-service-header-event', new lang_string('edulevel', 'moodle'));
|
||||||
|
|
||||||
/* List of events */
|
/* List of events */
|
||||||
$event_list = report_eventlist_list_generator::get_all_events_list(true);
|
$eventlist = report_eventlist_list_generator::get_all_events_list(true);
|
||||||
|
|
||||||
$events = array();
|
$events = array();
|
||||||
foreach ($event_list as $event) {
|
foreach ($eventlist as $event) {
|
||||||
$events[$event['component']][] =& $m_form->createElement('checkbox', $event['eventname'], $event['eventname']);
|
$events[$event['component']][] =& $mform->createElement('checkbox', $event['eventname'], $event['eventname']);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($events as $key => $event) {
|
foreach ($events as $key => $event) {
|
||||||
$m_form->addGroup($event, 'events', $key, '<br />', true);
|
$mform->addGroup($event, 'events', $key, '<br />', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Control Panel */
|
/* Control Panel */
|
||||||
|
@ -36,24 +36,24 @@ require_once($CFG->libdir . '/tablelib.php');
|
|||||||
*/
|
*/
|
||||||
class local_webhooks_services_table extends table_sql {
|
class local_webhooks_services_table extends table_sql {
|
||||||
/**
|
/**
|
||||||
* @var string $main_page
|
* @var string $mainpage
|
||||||
*/
|
*/
|
||||||
protected static $main_page = '/local/webhooks/index.php';
|
protected static $mainpage = '/local/webhooks/index.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $editor_page
|
* @var string $editorpage
|
||||||
*/
|
*/
|
||||||
protected static $editor_page = '/local/webhooks/service.php';
|
protected static $editorpage = '/local/webhooks/service.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $unique_id
|
* @param string $uniqueid
|
||||||
*
|
*
|
||||||
* @throws \coding_exception
|
* @throws \coding_exception
|
||||||
*/
|
*/
|
||||||
public function __construct($unique_id = '') {
|
public function __construct($uniqueid = '') {
|
||||||
parent::__construct($unique_id);
|
parent::__construct($uniqueid);
|
||||||
$this->define_table_columns();
|
$this->define_table_columns();
|
||||||
$this->define_table_configs();
|
$this->define_table_configs();
|
||||||
}
|
}
|
||||||
@ -61,12 +61,12 @@ class local_webhooks_services_table extends table_sql {
|
|||||||
/**
|
/**
|
||||||
* Query the database for results to display in the table.
|
* Query the database for results to display in the table.
|
||||||
*
|
*
|
||||||
* @param int $page_size
|
* @param int $pagesize
|
||||||
* @param boolean $use_initials_bar
|
* @param boolean $useinitialsbar
|
||||||
*
|
*
|
||||||
* @throws \dml_exception
|
* @throws \dml_exception
|
||||||
*/
|
*/
|
||||||
public function query_db($page_size = 0, $use_initials_bar = false) {
|
public function query_db($pagesize = 0, $useinitialsbar = false) {
|
||||||
$this->rawdata = local_webhooks_api::get_services(array(), $this->get_page_start(), $this->get_page_size());
|
$this->rawdata = local_webhooks_api::get_services(array(), $this->get_page_start(), $this->get_page_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,27 +116,27 @@ class local_webhooks_services_table extends table_sql {
|
|||||||
public function col_actions($row) {
|
public function col_actions($row) {
|
||||||
global $OUTPUT;
|
global $OUTPUT;
|
||||||
|
|
||||||
$hide_show_icon = 't/show';
|
$hideshowicon = 't/show';
|
||||||
$hide_show_string = new lang_string('enable', 'moodle');
|
$hideshowstring = new lang_string('enable', 'moodle');
|
||||||
|
|
||||||
if (!empty($row->status)) {
|
if (!empty($row->status)) {
|
||||||
$hide_show_icon = 't/hide';
|
$hideshowicon = 't/hide';
|
||||||
$hide_show_string = new lang_string('disable', 'moodle');
|
$hideshowstring = new lang_string('disable', 'moodle');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Link for activation / deactivation */
|
/* Link for activation / deactivation */
|
||||||
$hide_show_link = new moodle_url(self::$main_page, array('hideshowid' => $row->id, 'sesskey' => sesskey()));
|
$hideshowlink = new moodle_url(self::$mainpage, array('hideshowid' => $row->id, 'sesskey' => sesskey()));
|
||||||
$hide_show_item = $OUTPUT->action_icon($hide_show_link, new pix_icon($hide_show_icon, $hide_show_string));
|
$hideshowitem = $OUTPUT->action_icon($hideshowlink, new pix_icon($hideshowicon, $hideshowstring));
|
||||||
|
|
||||||
/* Link for editing */
|
/* Link for editing */
|
||||||
$edit_link = new moodle_url(self::$editor_page, array('serviceid' => $row->id, 'sesskey' => sesskey()));
|
$editlink = new moodle_url(self::$editorpage, array('serviceid' => $row->id, 'sesskey' => sesskey()));
|
||||||
$edit_item = $OUTPUT->action_icon($edit_link, new pix_icon('t/edit', new lang_string('edit', 'moodle')));
|
$edititem = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', new lang_string('edit', 'moodle')));
|
||||||
|
|
||||||
/* Link to remove */
|
/* Link to remove */
|
||||||
$delete_link = new moodle_url(self::$main_page, array('deleteid' => $row->id, 'sesskey' => sesskey()));
|
$deletelink = new moodle_url(self::$mainpage, array('deleteid' => $row->id, 'sesskey' => sesskey()));
|
||||||
$delete_item = $OUTPUT->action_icon($delete_link, new pix_icon('t/delete', new lang_string('delete', 'moodle')));
|
$deleteitem = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', new lang_string('delete', 'moodle')));
|
||||||
|
|
||||||
return $hide_show_item . $edit_item . $delete_item;
|
return $hideshowitem . $edititem . $deleteitem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,7 +159,7 @@ class local_webhooks_services_table extends table_sql {
|
|||||||
* @throws \moodle_exception
|
* @throws \moodle_exception
|
||||||
*/
|
*/
|
||||||
public function col_name($row) {
|
public function col_name($row) {
|
||||||
$link = new moodle_url(self::$editor_page, array('serviceid' => $row->id, 'sesskey' => sesskey()));
|
$link = new moodle_url(self::$editorpage, array('serviceid' => $row->id, 'sesskey' => sesskey()));
|
||||||
|
|
||||||
return html_writer::link($link, $row->name);
|
return html_writer::link($link, $row->name);
|
||||||
}
|
}
|
||||||
|
@ -27,18 +27,18 @@ defined('MOODLE_INTERNAL') || die();
|
|||||||
/**
|
/**
|
||||||
* Function to upgrade 'local_webhooks'.
|
* Function to upgrade 'local_webhooks'.
|
||||||
*
|
*
|
||||||
* @param int $old_version
|
* @param int $oldversion
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @throws \dml_exception
|
* @throws \dml_exception
|
||||||
* @throws \downgrade_exception
|
* @throws \downgrade_exception
|
||||||
* @throws \upgrade_exception
|
* @throws \upgrade_exception
|
||||||
*/
|
*/
|
||||||
function xmldb_local_webhooks_upgrade($old_version = 0) {
|
function xmldb_local_webhooks_upgrade($oldversion = 0) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
/* Update from versions 3.* */
|
/* Update from versions 3.* */
|
||||||
if ($old_version < 2017112600 || $old_version === 2018061900) {
|
if ($oldversion < 2017112600 || $oldversion === 2018061900) {
|
||||||
$rs = $DB->get_recordset('local_webhooks_service', null, 'id', '*', 0, 0);
|
$rs = $DB->get_recordset('local_webhooks_service', null, 'id', '*', 0, 0);
|
||||||
|
|
||||||
foreach ($rs as $record) {
|
foreach ($rs as $record) {
|
||||||
@ -55,15 +55,15 @@ function xmldb_local_webhooks_upgrade($old_version = 0) {
|
|||||||
|
|
||||||
/* Update from version 4.0.0-rc.1 */
|
/* Update from version 4.0.0-rc.1 */
|
||||||
|
|
||||||
/* if ($old_version === 2017122900) {} */
|
/* if ($oldversion === 2017122900) {} */
|
||||||
|
|
||||||
/* Update from version 4.0.0-rc.2 */
|
/* Update from version 4.0.0-rc.2 */
|
||||||
|
|
||||||
/* if ($old_version === 2018022200) {} */
|
/* if ($oldversion === 2018022200) {} */
|
||||||
|
|
||||||
/* Update from version 4.0.0-rc.3 */
|
/* Update from version 4.0.0-rc.3 */
|
||||||
|
|
||||||
/* if ($old_version === 2018022500) {} */
|
/* if ($oldversion === 2018022500) {} */
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
32
index.php
32
index.php
@ -28,47 +28,47 @@ require_once($CFG->dirroot . '/local/webhooks/classes/ui_tables_plugin.php');
|
|||||||
require_once($CFG->dirroot . '/local/webhooks/lib.php');
|
require_once($CFG->dirroot . '/local/webhooks/lib.php');
|
||||||
require_once($CFG->libdir . '/adminlib.php');
|
require_once($CFG->libdir . '/adminlib.php');
|
||||||
|
|
||||||
$delete_id = optional_param('deleteid', 0, PARAM_INT);
|
$deleteid = optional_param('deleteid', 0, PARAM_INT);
|
||||||
$hide_show_id = optional_param('hideshowid', 0, PARAM_INT);
|
$hideshowid = optional_param('hideshowid', 0, PARAM_INT);
|
||||||
|
|
||||||
$edit_page = '/local/webhooks/service.php';
|
$editpage = '/local/webhooks/service.php';
|
||||||
$main_page = '/local/webhooks/index.php';
|
$mainpage = '/local/webhooks/index.php';
|
||||||
$base_url = new moodle_url($main_page);
|
$baseurl = new moodle_url($mainpage);
|
||||||
|
|
||||||
admin_externalpage_setup('local_webhooks', '', null, $base_url, array());
|
admin_externalpage_setup('local_webhooks', '', null, $baseurl, array());
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
|
||||||
/* Remove the service */
|
/* Remove the service */
|
||||||
if (!empty($delete_id) && confirm_sesskey()) {
|
if (!empty($deleteid) && confirm_sesskey()) {
|
||||||
local_webhooks_api::delete_service($delete_id);
|
local_webhooks_api::delete_service($deleteid);
|
||||||
redirect($PAGE->url, new lang_string('deleted', 'moodle'));
|
redirect($PAGE->url, new lang_string('deleted', 'moodle'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable / Enable the service */
|
/* Disable / Enable the service */
|
||||||
if (!empty($hide_show_id) && confirm_sesskey()) {
|
if (!empty($hideshowid) && confirm_sesskey()) {
|
||||||
$service = local_webhooks_api::get_service($hide_show_id);
|
$service = local_webhooks_api::get_service($hideshowid);
|
||||||
$service->status = !(bool) $service->status;
|
$service->status = !(bool) $service->status;
|
||||||
local_webhooks_api::update_service((array) $service);
|
local_webhooks_api::update_service((array) $service);
|
||||||
redirect($PAGE->url, new lang_string('changessaved', 'moodle'));
|
redirect($PAGE->url, new lang_string('changessaved', 'moodle'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The page title */
|
/* The page title */
|
||||||
$title_page = new lang_string('pluginname', 'local_webhooks');
|
$titlepage = new lang_string('pluginname', 'local_webhooks');
|
||||||
$PAGE->set_heading($title_page);
|
$PAGE->set_heading($titlepage);
|
||||||
$PAGE->set_title($title_page);
|
$PAGE->set_title($titlepage);
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
/* Displays the table */
|
/* Displays the table */
|
||||||
$table = new local_webhooks_services_table('local-webhooks-table');
|
$table = new local_webhooks_services_table('local-webhooks-table');
|
||||||
$table->define_baseurl($base_url);
|
$table->define_baseurl($baseurl);
|
||||||
$table->out(25, true);
|
$table->out(25, true);
|
||||||
|
|
||||||
/* Separation */
|
/* Separation */
|
||||||
echo html_writer::empty_tag('br');
|
echo html_writer::empty_tag('br');
|
||||||
|
|
||||||
/* Adds the add button */
|
/* Adds the add button */
|
||||||
$add_service_url = new moodle_url($edit_page, array('sesskey' => sesskey()));
|
$addserviceurl = new moodle_url($editpage, array('sesskey' => sesskey()));
|
||||||
echo $OUTPUT->single_button($add_service_url, new lang_string('add', 'moodle'));
|
echo $OUTPUT->single_button($addserviceurl, new lang_string('add', 'moodle'));
|
||||||
|
|
||||||
/* Footer */
|
/* Footer */
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
58
lib.php
58
lib.php
@ -38,21 +38,21 @@ class local_webhooks_api {
|
|||||||
/**
|
/**
|
||||||
* Get information about the service.
|
* Get information about the service.
|
||||||
*
|
*
|
||||||
* @param int $service_id
|
* @param int $serviceid
|
||||||
*
|
*
|
||||||
* @return object
|
* @return object
|
||||||
* @throws \dml_exception
|
* @throws \dml_exception
|
||||||
* @throws \moodle_exception
|
* @throws \moodle_exception
|
||||||
*/
|
*/
|
||||||
public static function get_service($service_id = 0) {
|
public static function get_service($serviceid = 0) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
if (!is_numeric($service_id) || $service_id === 0) {
|
if (!is_numeric($serviceid) || $serviceid === 0) {
|
||||||
print_error('unknowparamtype', 'error', null, 'service_id');
|
print_error('unknowparamtype', 'error', null, 'serviceid');
|
||||||
}
|
}
|
||||||
|
|
||||||
$service = $DB->get_record(LW_TABLE_SERVICES, array('id' => $service_id), '*', MUST_EXIST);
|
$service = $DB->get_record(LW_TABLE_SERVICES, array('id' => $serviceid), '*', MUST_EXIST);
|
||||||
$events = $DB->get_records(LW_TABLE_EVENTS, array('serviceid' => $service_id), '', '*', 0, 0);
|
$events = $DB->get_records(LW_TABLE_EVENTS, array('serviceid' => $serviceid), '', '*', 0, 0);
|
||||||
|
|
||||||
$service->events = array();
|
$service->events = array();
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
@ -67,16 +67,16 @@ class local_webhooks_api {
|
|||||||
* By default, the entire list of services is given.
|
* By default, the entire list of services is given.
|
||||||
*
|
*
|
||||||
* @param array $conditions
|
* @param array $conditions
|
||||||
* @param int $limit_from
|
* @param int $limitfrom
|
||||||
* @param int $limit_num
|
* @param int $limitnum
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \dml_exception
|
* @throws \dml_exception
|
||||||
*/
|
*/
|
||||||
public static function get_services(array $conditions = array(), $limit_from = 0, $limit_num = 0) {
|
public static function get_services(array $conditions = array(), $limitfrom = 0, $limitnum = 0) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$services = $DB->get_records(LW_TABLE_SERVICES, $conditions, '', '*', $limit_from, $limit_num);
|
$services = $DB->get_records(LW_TABLE_SERVICES, $conditions, '', '*', $limitfrom, $limitnum);
|
||||||
|
|
||||||
foreach ($services as $service) {
|
foreach ($services as $service) {
|
||||||
$events = $DB->get_records(LW_TABLE_EVENTS, array('serviceid' => $service->id), '', '*', 0, 0);
|
$events = $DB->get_records(LW_TABLE_EVENTS, array('serviceid' => $service->id), '', '*', 0, 0);
|
||||||
@ -93,20 +93,20 @@ class local_webhooks_api {
|
|||||||
/**
|
/**
|
||||||
* Get the list of services subscribed to the event.
|
* Get the list of services subscribed to the event.
|
||||||
*
|
*
|
||||||
* @param string $event_name
|
* @param string $eventname
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \dml_exception
|
* @throws \dml_exception
|
||||||
* @throws \moodle_exception
|
* @throws \moodle_exception
|
||||||
*/
|
*/
|
||||||
public static function get_services_by_event($event_name = '') {
|
public static function get_services_by_event($eventname = '') {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
if (!is_string($event_name) || $event_name === '') {
|
if (!is_string($eventname) || $eventname === '') {
|
||||||
print_error('unknowparamtype', 'error', null, 'event_name');
|
print_error('unknowparamtype', 'error', null, 'eventname');
|
||||||
}
|
}
|
||||||
|
|
||||||
$events = $DB->get_records(LW_TABLE_EVENTS, array('name' => $event_name), '', '*', 0, 0);
|
$events = $DB->get_records(LW_TABLE_EVENTS, array('name' => $eventname), '', '*', 0, 0);
|
||||||
|
|
||||||
$services = array();
|
$services = array();
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
@ -132,37 +132,37 @@ class local_webhooks_api {
|
|||||||
print_error('unknowparamtype', 'error', null, 'service');
|
print_error('unknowparamtype', 'error', null, 'service');
|
||||||
}
|
}
|
||||||
|
|
||||||
$service_id = $DB->insert_record(LW_TABLE_SERVICES, (object) $service, true, false);
|
$serviceid = $DB->insert_record(LW_TABLE_SERVICES, (object) $service, true, false);
|
||||||
if ($service_id && !empty($service['events']) && is_array($service['events'])) {
|
if ($serviceid && !empty($service['events']) && is_array($service['events'])) {
|
||||||
self::insert_events($service['events'], $service_id);
|
self::insert_events($service['events'], $serviceid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Mark the log.
|
// TODO: Mark the log.
|
||||||
|
|
||||||
return (int) $service_id;
|
return (int) $serviceid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the service data from the database.
|
* Delete the service data from the database.
|
||||||
*
|
*
|
||||||
* @param int $service_id
|
* @param int $serviceid
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \dml_exception
|
* @throws \dml_exception
|
||||||
* @throws \moodle_exception
|
* @throws \moodle_exception
|
||||||
*/
|
*/
|
||||||
public static function delete_service($service_id = 0) {
|
public static function delete_service($serviceid = 0) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
if (!is_numeric($service_id) || $service_id === 0) {
|
if (!is_numeric($serviceid) || $serviceid === 0) {
|
||||||
print_error('unknowparamtype', 'error', null, 'service_id');
|
print_error('unknowparamtype', 'error', null, 'serviceid');
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Mark the log.
|
// TODO: Mark the log.
|
||||||
|
|
||||||
$DB->delete_records(LW_TABLE_EVENTS, array('serviceid' => $service_id));
|
$DB->delete_records(LW_TABLE_EVENTS, array('serviceid' => $serviceid));
|
||||||
|
|
||||||
return $DB->delete_records(LW_TABLE_SERVICES, array('id' => $service_id));
|
return $DB->delete_records(LW_TABLE_SERVICES, array('id' => $serviceid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,17 +198,17 @@ class local_webhooks_api {
|
|||||||
* Save the list of events to the database.
|
* Save the list of events to the database.
|
||||||
*
|
*
|
||||||
* @param array $events
|
* @param array $events
|
||||||
* @param int $service_id
|
* @param int $serviceid
|
||||||
*
|
*
|
||||||
* @throws \coding_exception
|
* @throws \coding_exception
|
||||||
* @throws \dml_exception
|
* @throws \dml_exception
|
||||||
*/
|
*/
|
||||||
protected static function insert_events(array $events = array(), $service_id = 0) {
|
protected static function insert_events(array $events = array(), $serviceid = 0) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$conditions = array();
|
$conditions = array();
|
||||||
foreach ($events as $event_name) {
|
foreach ($events as $eventname) {
|
||||||
$conditions[] = array('name' => $event_name, 'serviceid' => $service_id);
|
$conditions[] = array('name' => $eventname, 'serviceid' => $serviceid);
|
||||||
}
|
}
|
||||||
|
|
||||||
$DB->insert_records(LW_TABLE_EVENTS, $conditions);
|
$DB->insert_records(LW_TABLE_EVENTS, $conditions);
|
||||||
|
50
service.php
50
service.php
@ -28,55 +28,55 @@ require_once($CFG->dirroot . '/local/webhooks/classes/ui_forms_plugin.php');
|
|||||||
require_once($CFG->dirroot . '/local/webhooks/lib.php');
|
require_once($CFG->dirroot . '/local/webhooks/lib.php');
|
||||||
require_once($CFG->libdir . '/adminlib.php');
|
require_once($CFG->libdir . '/adminlib.php');
|
||||||
|
|
||||||
$service_id = optional_param('serviceid', 0, PARAM_INT);
|
$serviceid = optional_param('serviceid', 0, PARAM_INT);
|
||||||
|
|
||||||
$url_parameters = array('serviceid' => $service_id);
|
$urlparameters = array('serviceid' => $serviceid);
|
||||||
$base_url = new moodle_url('/local/webhooks/service.php', $url_parameters);
|
$baseurl = new moodle_url('/local/webhooks/service.php', $urlparameters);
|
||||||
$main_page = new moodle_url('/local/webhooks/index.php');
|
$mainpage = new moodle_url('/local/webhooks/index.php');
|
||||||
|
|
||||||
admin_externalpage_setup('local_webhooks', '', null, $base_url, array());
|
admin_externalpage_setup('local_webhooks', '', null, $baseurl, array());
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
|
||||||
$m_form = new local_webhooks_service_edit_form($PAGE->url);
|
$mform = new local_webhooks_service_edit_form($PAGE->url);
|
||||||
$form_data = (array) $m_form->get_data();
|
$formdata = (array) $mform->get_data();
|
||||||
|
|
||||||
/* Cancel */
|
/* Cancel */
|
||||||
if ($m_form->is_cancelled()) {
|
if ($mform->is_cancelled()) {
|
||||||
redirect($main_page);
|
redirect($mainpage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Updating the data */
|
/* Updating the data */
|
||||||
if (!empty($form_data) && confirm_sesskey()) {
|
if (!empty($formdata) && confirm_sesskey()) {
|
||||||
if (isset($form_data['events'])) {
|
if (isset($formdata['events'])) {
|
||||||
$form_data['events'] = array_keys($form_data['events']);
|
$formdata['events'] = array_keys($formdata['events']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($service_id)) {
|
if (!empty($serviceid)) {
|
||||||
$form_data['id'] = $service_id;
|
$formdata['id'] = $serviceid;
|
||||||
local_webhooks_api::update_service($form_data);
|
local_webhooks_api::update_service($formdata);
|
||||||
} else {
|
} else {
|
||||||
local_webhooks_api::create_service($form_data);
|
local_webhooks_api::create_service($formdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect($main_page, new lang_string('changessaved', 'moodle'));
|
redirect($mainpage, new lang_string('changessaved', 'moodle'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loading service data */
|
/* Loading service data */
|
||||||
if (!empty($service_id)) {
|
if (!empty($serviceid)) {
|
||||||
$service = local_webhooks_api::get_service($service_id);
|
$service = local_webhooks_api::get_service($serviceid);
|
||||||
$service->events = array_fill_keys($service->events, 1);
|
$service->events = array_fill_keys($service->events, 1);
|
||||||
$m_form->set_data($service);
|
$mform->set_data($service);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The page title */
|
/* The page title */
|
||||||
$title_page = new lang_string('externalservice', 'webservice');
|
$titlepage = new lang_string('externalservice', 'webservice');
|
||||||
$PAGE->navbar->add($title_page);
|
$PAGE->navbar->add($titlepage);
|
||||||
$PAGE->set_heading($title_page);
|
$PAGE->set_heading($titlepage);
|
||||||
$PAGE->set_title($title_page);
|
$PAGE->set_title($titlepage);
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
/* Displays the form */
|
/* Displays the form */
|
||||||
$m_form->display();
|
$mform->display();
|
||||||
|
|
||||||
/* Footer */
|
/* Footer */
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
Loading…
x
Reference in New Issue
Block a user