Code style fix

Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
Valentin Popov 2018-10-22 02:17:12 +04:00
parent f3b5ab5616
commit 1352b5ee79
Signed by: Valentin Popov
GPG Key ID: 269A00ACA90A8EA3
13 changed files with 250 additions and 206 deletions

View File

@ -24,7 +24,7 @@
namespace local_webhooks;
defined( "MOODLE_INTERNAL" ) || die();
defined('MOODLE_INTERNAL') || die();
/**
* Defines event handlers.
@ -40,9 +40,9 @@ class event_observer {
*
* @param object $event
*/
public static function observe_all( $event ) {
public static function observe_all($event) {
$task = new \local_webhooks\task\process_events_task();
$task->set_custom_data( $event->get_data() );
\core\task\manager::queue_adhoc_task( $task );
$task->set_custom_data($event->get_data());
\core\task\manager::queue_adhoc_task($task);
}
}

View File

@ -24,7 +24,11 @@
namespace local_webhooks\task;
defined( "MOODLE_INTERNAL" ) || die();
global $CFG;
require_once $CFG->dirroot . '/local/webhooks/lib.php';
defined('MOODLE_INTERNAL') || die();
/**
* Class process_events_task
@ -36,26 +40,25 @@ defined( "MOODLE_INTERNAL" ) || die();
class process_events_task extends \core\task\adhoc_task {
/**
* Task handler.
*
* @throws \dml_exception
* @throws \moodle_exception
*/
public function execute() {
global $CFG;
$services = \local_webhooks_api::get_services_by_event($this->get_custom_data()->eventname);
require_once( $CFG->dirroot . "/local/webhooks/lib.php" );
$services = \local_webhooks_api::get_services_by_event( $this->get_custom_data()->eventname );
foreach ( $services as $service ) {
if ( empty( $service->status ) ) {
foreach ($services as $service) {
if ((bool) $service->status !== true) {
return;
}
$curl = new \curl();
$event = (array) $this->get_custom_data();
$event[ "token" ] = $service->token;
$event['token'] = $service->token;
$curl->setHeader( array( "Content-Type: " . $service->header ) );
$curl->post( $service->point, json_encode( $event ) );
$curl->setHeader(array('Content-Type: ' . $service->header));
$curl->post($service->point, json_encode($event));
// TODO: Mark the log
$curl->getResponse();

View File

@ -22,10 +22,10 @@
* @package local_webhooks
*/
defined( "MOODLE_INTERNAL" ) || die();
defined('MOODLE_INTERNAL') || die();
require_once( $CFG->dirroot . "/local/webhooks/lib.php" );
require_once( $CFG->libdir . "/formslib.php" );
require_once $CFG->dirroot . '/local/webhooks/lib.php';
require_once $CFG->libdir . '/formslib.php';
/**
* Description editing form definition.
@ -38,66 +38,68 @@ class local_webhooks_service_edit_form extends moodleform {
/**
* @param string $baseUrl
*/
public function __construct( $baseUrl ) {
parent::__construct( $baseUrl );
public function __construct($baseUrl) {
parent::__construct($baseUrl);
}
/**
* Defines the standard structure of the form.
*
* @throws \coding_exception
*/
protected function definition() {
$mForm =& $this->_form;
$size = array( "size" => 60 );
$size = array('size' => 60);
/* Form heading */
$mForm->addElement( "header", "editserviceheadermain", new lang_string( "service", "webservice" ) );
$mForm->addElement('header', 'editserviceheadermain', new lang_string('service', 'webservice'));
/* Name of the service */
$mForm->addElement( "text", "name", new lang_string( "name", "moodle" ), $size );
$mForm->addRule( "name", null, "required" );
$mForm->setType( "name", PARAM_RAW );
$mForm->addElement('text', 'name', new lang_string('name', 'moodle'), $size);
$mForm->addRule('name', null, 'required');
$mForm->setType('name', PARAM_RAW);
/* Callback address */
$mForm->addElement( "text", "point", new lang_string( "url", "moodle" ), $size );
$mForm->addRule( "point", null, "required" );
$mForm->setType( "point", PARAM_URL );
$mForm->addElement('text', 'point', new lang_string('url', 'moodle'), $size);
$mForm->addRule('point', null, 'required');
$mForm->setType('point', PARAM_URL);
/* Enabling the service */
$mForm->addElement( "advcheckbox", "status", new lang_string( "enable", "moodle" ) );
$mForm->setType( "status", PARAM_BOOL );
$mForm->setDefault( "status", 1 );
$mForm->setAdvanced( "status" );
$mForm->addElement('advcheckbox', 'status', new lang_string('enable', 'moodle'));
$mForm->setType('status', PARAM_BOOL);
$mForm->setDefault('status', 1);
$mForm->setAdvanced('status');
/* Token */
$mForm->addElement( "text", "token", new lang_string( "token", "webservice" ), $size );
$mForm->addRule( "token", null, "required" );
$mForm->setType( "token", PARAM_RAW );
$mForm->addElement('text', 'token', new lang_string('token', 'webservice'), $size);
$mForm->addRule('token', null, 'required');
$mForm->setType('token', PARAM_RAW);
/* Content type */
$contentType = array(
"application/json" => "application/json",
"application/x-www-form-urlencoded" => "application/x-www-form-urlencoded",
'application/json' => 'application/json',
'application/x-www-form-urlencoded' => 'application/x-www-form-urlencoded',
);
$mForm->addElement( "select", "header", "Content-Type", $contentType );
$mForm->setAdvanced( "header" );
$mForm->addElement('select', 'header', 'Content-Type', $contentType);
$mForm->setAdvanced('header');
/* Form heading */
$mForm->addElement( "header", "editserviceheaderevent", new lang_string( "edulevel", "moodle" ) );
$mForm->addElement('header', 'editserviceheaderevent', new lang_string('edulevel', 'moodle'));
/* List of events */
$eventList = report_eventlist_list_generator::get_all_events_list( true );
$eventList = report_eventlist_list_generator::get_all_events_list(true);
$events = array();
foreach ( $eventList as $event ) {
$events[ $event[ "component" ] ][] =& $mForm->createElement( "checkbox", $event[ "eventname" ], $event[ "eventname" ] );
foreach ($eventList as $event) {
$events[$event['component']][] =& $mForm->createElement('checkbox', $event['eventname'], $event['eventname']);
}
foreach ( $events as $key => $event ) {
$mForm->addGroup( $event, "events", $key, "<br />", true );
foreach ($events as $key => $event) {
$mForm->addGroup($event, 'events', $key, '<br />', true);
}
/* Control Panel */
$this->add_action_buttons( true );
$this->add_action_buttons(true);
}
}
}

View File

@ -22,10 +22,10 @@
* @package local_webhooks
*/
defined( "MOODLE_INTERNAL" ) || die();
defined('MOODLE_INTERNAL') || die();
require_once( $CFG->dirroot . "/local/webhooks/lib.php" );
require_once( $CFG->libdir . "/tablelib.php" );
require_once $CFG->dirroot . '/local/webhooks/lib.php';
require_once $CFG->libdir . '/tablelib.php';
/**
* Display the list of services table.
@ -38,20 +38,22 @@ class local_webhooks_services_table extends table_sql {
/**
* @var string $mainPage
*/
protected static $mainPage = "/local/webhooks/index.php";
protected static $mainPage = '/local/webhooks/index.php';
/**
* @var string $editorPage
*/
protected static $editorPage = "/local/webhooks/service.php";
protected static $editorPage = '/local/webhooks/service.php';
/**
* Constructor.
*
* @param string $uniqueId
*
* @throws \coding_exception
*/
public function __construct( $uniqueId = "" ) {
parent::__construct( $uniqueId );
public function __construct($uniqueId = '') {
parent::__construct($uniqueId);
$this->define_table_columns();
$this->define_table_configs();
}
@ -59,73 +61,80 @@ class local_webhooks_services_table extends table_sql {
/**
* Query the database for results to display in the table.
*
* @param number $pageSize
* @param int $pageSize
* @param boolean $useInitialsBar
*
* @throws \dml_exception
*/
public function query_db( $pageSize = 0, $useInitialsBar = false ) {
$this->rawdata = local_webhooks_api::get_services( array(), $this->get_page_start(), $this->get_page_size() );
public function query_db($pageSize = 0, $useInitialsBar = false) {
$this->rawdata = local_webhooks_api::get_services(array(), $this->get_page_start(), $this->get_page_size());
}
/**
* Defines the basic settings of the table.
*/
public function define_table_configs() {
$this->collapsible( false );
$this->is_downloadable( false );
$this->no_sorting( "actions" );
$this->pageable( true );
$this->collapsible(false);
$this->is_downloadable(false);
$this->no_sorting('actions');
$this->pageable(true);
}
/**
* Defines the main columns and table headers.
*
* @throws \coding_exception
*/
public function define_table_columns() {
$columns = array(
"name",
"point",
"events",
"actions"
'name',
'point',
'events',
'actions',
);
$headers = array(
new lang_string( "name", "moodle" ),
new lang_string( "url", "moodle" ),
new lang_string( "edulevel", "moodle" ),
new lang_string( "actions", "moodle" )
new lang_string('name', 'moodle'),
new lang_string('url', 'moodle'),
new lang_string('edulevel', 'moodle'),
new lang_string('actions', 'moodle'),
);
$this->define_columns( $columns );
$this->define_headers( $headers );
$this->define_columns($columns);
$this->define_headers($headers);
}
/**
* Specifies the display of a column with actions.
*
* @param object $row
*
* @return string
* @throws \coding_exception
* @throws \moodle_exception
*/
public function col_actions( $row ) {
public function col_actions($row) {
global $OUTPUT;
$hideShowIcon = "t/show";
$hideShowString = new lang_string( "enable", "moodle" );
$hideShowIcon = 't/show';
$hideShowString = new lang_string('enable', 'moodle');
if ( !empty( $row->status ) ) {
$hideShowIcon = "t/hide";
$hideShowString = new lang_string( "disable", "moodle" );
if (!empty($row->status)) {
$hideShowIcon = 't/hide';
$hideShowString = new lang_string('disable', 'moodle');
}
/* Link for activation / deactivation */
$hideShowLink = new moodle_url( self::$mainPage, array( "hideshowid" => $row->id, "sesskey" => sesskey() ) );
$hideShowItem = $OUTPUT->action_icon( $hideShowLink, new pix_icon( $hideShowIcon, $hideShowString ) );
$hideShowLink = new moodle_url(self::$mainPage, array('hideshowid' => $row->id, 'sesskey' => sesskey()));
$hideShowItem = $OUTPUT->action_icon($hideShowLink, new pix_icon($hideShowIcon, $hideShowString));
/* Link for editing */
$editLink = new moodle_url( self::$editorPage, array( "serviceid" => $row->id, "sesskey" => sesskey() ) );
$editItem = $OUTPUT->action_icon( $editLink, new pix_icon( "t/edit", new lang_string( "edit", "moodle" ) ) );
$editLink = new moodle_url(self::$editorPage, array('serviceid' => $row->id, 'sesskey' => sesskey()));
$editItem = $OUTPUT->action_icon($editLink, new pix_icon('t/edit', new lang_string('edit', 'moodle')));
/* Link to remove */
$deleteLink = new moodle_url( self::$mainPage, array( "deleteid" => $row->id, "sesskey" => sesskey() ) );
$deleteItem = $OUTPUT->action_icon( $deleteLink, new pix_icon( "t/delete", new lang_string( "delete", "moodle" ) ) );
$deleteLink = new moodle_url(self::$mainPage, array('deleteid' => $row->id, 'sesskey' => sesskey()));
$deleteItem = $OUTPUT->action_icon($deleteLink, new pix_icon('t/delete', new lang_string('delete', 'moodle')));
return $hideShowItem . $editItem . $deleteItem;
}
@ -134,20 +143,24 @@ class local_webhooks_services_table extends table_sql {
* Specifies the display of a column with events.
*
* @param object $row
*
* @return number
*/
public function col_events( $row ) {
return count( $row->events );
public function col_events($row) {
return count($row->events);
}
/**
* Specifies the display of the column with the service name.
*
* @param object $row
*
* @return string
* @throws \moodle_exception
*/
public function col_name( $row ) {
$link = new moodle_url( self::$editorPage, array( "serviceid" => $row->id, "sesskey" => sesskey() ) );
return html_writer::link( $link, $row->name );
public function col_name($row) {
$link = new moodle_url(self::$editorPage, array('serviceid' => $row->id, 'sesskey' => sesskey()));
return html_writer::link($link, $row->name);
}
}

View File

@ -22,11 +22,11 @@
* @package local_webhooks
*/
defined( "MOODLE_INTERNAL" ) || die();
defined('MOODLE_INTERNAL') || die();
$observers = array(
array(
"callback" => "\local_webhooks\\event_observer::observe_all",
"eventname" => "*"
)
'callback' => '\local_webhooks\event_observer::observe_all',
'eventname' => '*',
),
);

View File

@ -22,6 +22,6 @@
* @package local_webhooks
*/
defined( "MOODLE_INTERNAL" ) || die();
defined('MOODLE_INTERNAL') || die();
$functions = array();

View File

@ -22,9 +22,9 @@
* @package local_webhooks
*/
defined( "MOODLE_INTERNAL" ) || die();
defined('MOODLE_INTERNAL') || die();
require_once( $CFG->libdir . "/externallib.php" );
require_once $CFG->libdir . '/externallib.php';
/**
* External functions.
@ -34,4 +34,4 @@ require_once( $CFG->libdir . "/externallib.php" );
* @package local_webhooks
*/
class local_webhooks_external extends external_api {
}
}

View File

@ -22,53 +22,53 @@
* @package local_webhooks
*/
require_once( __DIR__ . "/../../config.php" );
require_once __DIR__ . '/../../config.php';
require_once( $CFG->dirroot . "/local/webhooks/classes/ui_tables_plugin.php" );
require_once( $CFG->dirroot . "/local/webhooks/lib.php" );
require_once( $CFG->libdir . "/adminlib.php" );
require_once $CFG->dirroot . '/local/webhooks/classes/ui_tables_plugin.php';
require_once $CFG->dirroot . '/local/webhooks/lib.php';
require_once $CFG->libdir . '/adminlib.php';
$deleteId = optional_param( "deleteid", 0, PARAM_INT );
$hideShowId = optional_param( "hideshowid", 0, PARAM_INT );
$deleteId = optional_param('deleteid', 0, PARAM_INT);
$hideShowId = optional_param('hideshowid', 0, PARAM_INT);
$editPage = "/local/webhooks/service.php";
$mainPage = "/local/webhooks/index.php";
$baseUrl = new moodle_url( $mainPage );
$editPage = '/local/webhooks/service.php';
$mainPage = '/local/webhooks/index.php';
$baseUrl = new moodle_url($mainPage);
admin_externalpage_setup( "local_webhooks", "", null, $baseUrl, array() );
admin_externalpage_setup('local_webhooks', '', null, $baseUrl, array());
$context = context_system::instance();
/* Remove the service */
if ( !empty( $deleteId ) && confirm_sesskey() ) {
local_webhooks_api::delete_service( $deleteId );
redirect( $PAGE->url, new lang_string( "deleted", "moodle" ) );
if (!empty($deleteId) && confirm_sesskey()) {
local_webhooks_api::delete_service($deleteId);
redirect($PAGE->url, new lang_string('deleted', 'moodle'));
}
/* Disable / Enable the service */
if ( !empty( $hideShowId ) && confirm_sesskey() ) {
$service = local_webhooks_api::get_service( $hideShowId );
if (!empty($hideShowId) && confirm_sesskey()) {
$service = local_webhooks_api::get_service($hideShowId);
$service->status = !(bool) $service->status;
local_webhooks_api::update_service( (array) $service );
redirect( $PAGE->url, new lang_string( "changessaved", "moodle" ) );
local_webhooks_api::update_service((array) $service);
redirect($PAGE->url, new lang_string('changessaved', 'moodle'));
}
/* The page title */
$titlePage = new lang_string( "pluginname", "local_webhooks" );
$PAGE->set_heading( $titlePage );
$PAGE->set_title( $titlePage );
$titlePage = new lang_string('pluginname', 'local_webhooks');
$PAGE->set_heading($titlePage);
$PAGE->set_title($titlePage);
echo $OUTPUT->header();
/* Displays the table */
$table = new local_webhooks_services_table( "local-webhooks-table" );
$table->define_baseurl( $baseUrl );
$table->out( 25, true );
$table = new local_webhooks_services_table('local-webhooks-table');
$table->define_baseurl($baseUrl);
$table->out(25, true);
/* Separation */
echo html_writer::empty_tag( "br" );
echo html_writer::empty_tag('br');
/* Adds the add button */
$addServiceUrl = new moodle_url( $editPage, array( "sesskey" => sesskey() ) );
echo $OUTPUT->single_button( $addServiceUrl, new lang_string( "add", "moodle" ) );
$addServiceUrl = new moodle_url($editPage, array('sesskey' => sesskey()));
echo $OUTPUT->single_button($addServiceUrl, new lang_string('add', 'moodle'));
/* Footer */
echo $OUTPUT->footer();

View File

@ -22,4 +22,4 @@
* @package local_webhooks
*/
$string[ "pluginname" ] = "WebHooks";
$string['pluginname'] = 'WebHooks';

108
lib.php
View File

@ -22,10 +22,10 @@
* @package local_webhooks
*/
defined( "MOODLE_INTERNAL" ) || die();
defined('MOODLE_INTERNAL') || die();
define( "LW_TABLE_SERVICES", "local_webhooks_service" );
define( "LW_TABLE_EVENTS", "local_webhooks_events" );
define('LW_TABLE_SERVICES', 'local_webhooks_service');
define('LW_TABLE_EVENTS', 'local_webhooks_events');
/**
* Class local_webhooks_api
@ -39,20 +39,23 @@ class local_webhooks_api {
* Get information about the service.
*
* @param int $serviceId
*
* @return object
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function get_service( $serviceId = 0 ) {
public static function get_service($serviceId = 0) {
global $DB;
if ( empty( $serviceId ) || !is_numeric( $serviceId ) ) {
print_error( "unknowparamtype", "error", null, "serviceId" );
if (!is_numeric($serviceId) || $serviceId === 0) {
print_error('unknowparamtype', 'error', null, 'serviceId');
}
$service = $DB->get_record( LW_TABLE_SERVICES, array( "id" => $serviceId ), "*", MUST_EXIST );
$events = $DB->get_records( LW_TABLE_EVENTS, array( "serviceid" => $serviceId ), "", "*", 0, 0 );
$service = $DB->get_record(LW_TABLE_SERVICES, array('id' => $serviceId), '*', MUST_EXIST);
$events = $DB->get_records(LW_TABLE_EVENTS, array('serviceid' => $serviceId), '', '*', 0, 0);
$service->events = array();
foreach ( $events as $event ) {
foreach ($events as $event) {
$service->events[] = $event->name;
}
@ -66,18 +69,20 @@ class local_webhooks_api {
* @param array $conditions
* @param int $limitFrom
* @param int $limitNum
*
* @return array
* @throws \dml_exception
*/
public static function get_services( $conditions = array(), $limitFrom = 0, $limitNum = 0 ) {
public static function get_services(array $conditions = array(), $limitFrom = 0, $limitNum = 0) {
global $DB;
$services = $DB->get_records( LW_TABLE_SERVICES, $conditions, "", "*", $limitFrom, $limitNum );
$services = $DB->get_records(LW_TABLE_SERVICES, $conditions, '', '*', $limitFrom, $limitNum);
foreach ( $services as $service ) {
$events = $DB->get_records( LW_TABLE_EVENTS, array( "serviceid" => $service->id ), "", "*", 0, 0 );
foreach ($services as $service) {
$events = $DB->get_records(LW_TABLE_EVENTS, array('serviceid' => $service->id), '', '*', 0, 0);
$service->events = array();
foreach ( $events as $event ) {
foreach ($events as $event) {
$service->events[] = $event->name;
}
}
@ -89,20 +94,23 @@ class local_webhooks_api {
* Get the list of services subscribed to the event.
*
* @param string $eventName
*
* @return array
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function get_services_by_event( $eventName = "" ) {
public static function get_services_by_event($eventName = '') {
global $DB;
if ( empty( $eventName ) || !is_string( $eventName ) ) {
print_error( "unknowparamtype", "error", null, "eventName" );
if (!is_string($eventName) || $eventName === '') {
print_error('unknowparamtype', 'error', null, 'eventName');
}
$events = $DB->get_records( LW_TABLE_EVENTS, array( "name" => $eventName ), "", "*", 0, 0 );
$events = $DB->get_records(LW_TABLE_EVENTS, array('name' => $eventName), '', '*', 0, 0);
$services = array();
foreach ( $events as $event ) {
$services[] = local_webhooks_api::get_service( $event->serviceid );
foreach ($events as $event) {
$services[] = self::get_service($event->serviceid);
}
return $services;
@ -112,18 +120,21 @@ class local_webhooks_api {
* Create service data in the database.
*
* @param array $service
*
* @return int
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function create_service( $service = array() ) {
public static function create_service(array $service = array()) {
global $DB;
if ( empty( $service ) || !is_array( $service ) ) {
print_error( "unknowparamtype", "error", null, "service" );
if (!is_array($service) || count($service) === 0) {
print_error('unknowparamtype', 'error', null, 'service');
}
$serviceId = $DB->insert_record( LW_TABLE_SERVICES, $service, true, false );
if ( $serviceId && !empty( $service[ "events" ] ) && is_array( $service[ "events" ] ) ) {
self::insert_events( $service[ "events" ], $serviceId );
$serviceId = $DB->insert_record(LW_TABLE_SERVICES, (object) $service, true, false);
if ($serviceId && !empty($service['events']) && is_array($service['events'])) {
self::insert_events($service['events'], $serviceId);
}
// TODO: Mark the log
@ -135,39 +146,47 @@ class local_webhooks_api {
* Delete the service data from the database.
*
* @param int $serviceId
*
* @return bool
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function delete_service( $serviceId = 0 ) {
public static function delete_service($serviceId = 0) {
global $DB;
if ( empty( $serviceId ) || !is_numeric( $serviceId ) ) {
print_error( "unknowparamtype", "error", null, "serviceId" );
if (!is_numeric($serviceId) || $serviceId === 0) {
print_error('unknowparamtype', 'error', null, 'serviceId');
}
// TODO: Mark the log
$DB->delete_records( LW_TABLE_EVENTS, array( "serviceid" => $serviceId ) );
return $DB->delete_records( LW_TABLE_SERVICES, array( "id" => $serviceId ) );
$DB->delete_records(LW_TABLE_EVENTS, array('serviceid' => $serviceId));
return $DB->delete_records(LW_TABLE_SERVICES, array('id' => $serviceId));
}
/**
* Update the service data in the database.
*
* @param array $service
*
* @return bool
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function update_service( $service = array() ) {
public static function update_service(array $service = array()) {
global $DB;
if ( empty( $service ) || !is_array( $service ) || empty( $service[ "id" ] ) ) {
print_error( "unknowparamtype", "error", null, "service" );
if (!is_array($service) || count($service) === 0 || !isset($service['id'])) {
print_error('unknowparamtype', 'error', null, 'service');
}
// TODO: Add transactions for operations
$result = $DB->update_record( LW_TABLE_SERVICES, $service, false );
$DB->delete_records( LW_TABLE_EVENTS, array( "serviceid" => $service[ "id" ] ) );
if ( $result && !empty( $service[ "events" ] ) && is_array( $service[ "events" ] ) ) {
self::insert_events( $service[ "events" ], $service[ "id" ] );
$result = $DB->update_record(LW_TABLE_SERVICES, (object) $service, false);
$DB->delete_records(LW_TABLE_EVENTS, array('serviceid' => $service['id']));
if ($result && is_array($service['events']) && count($service) !== 0) {
self::insert_events($service['events'], $service['id']);
}
// TODO: Mark the log
@ -180,15 +199,18 @@ class local_webhooks_api {
*
* @param array $events
* @param int $serviceId
*
* @throws \coding_exception
* @throws \dml_exception
*/
protected static function insert_events( $events = array(), $serviceId = 0 ) {
protected static function insert_events(array $events = array(), $serviceId = 0) {
global $DB;
$conditions = array();
foreach ( $events as $eventName ) {
$conditions[] = array( "name" => $eventName, "serviceid" => $serviceId );
foreach ($events as $eventName) {
$conditions[] = array('name' => $eventName, 'serviceid' => $serviceId);
}
$DB->insert_records( LW_TABLE_EVENTS, $conditions );
$DB->insert_records(LW_TABLE_EVENTS, $conditions);
}
}
}

View File

@ -22,57 +22,57 @@
* @package local_webhooks
*/
require_once( __DIR__ . "/../../config.php" );
require_once __DIR__ . '/../../config.php';
require_once( $CFG->dirroot . "/local/webhooks/classes/ui_forms_plugin.php" );
require_once( $CFG->dirroot . "/local/webhooks/lib.php" );
require_once( $CFG->libdir . "/adminlib.php" );
require_once $CFG->dirroot . '/local/webhooks/classes/ui_forms_plugin.php';
require_once $CFG->dirroot . '/local/webhooks/lib.php';
require_once $CFG->libdir . '/adminlib.php';
$serviceId = optional_param( "serviceid", 0, PARAM_INT );
$serviceId = optional_param('serviceid', 0, PARAM_INT);
$urlParameters = array( "serviceid" => $serviceId );
$baseUrl = new moodle_url( "/local/webhooks/service.php", $urlParameters );
$mainPage = new moodle_url( "/local/webhooks/index.php" );
$urlParameters = array('serviceid' => $serviceId);
$baseUrl = new moodle_url('/local/webhooks/service.php', $urlParameters);
$mainPage = new moodle_url('/local/webhooks/index.php');
admin_externalpage_setup( "local_webhooks", "", null, $baseUrl, array() );
admin_externalpage_setup('local_webhooks', '', null, $baseUrl, array());
$context = context_system::instance();
$mForm = new local_webhooks_service_edit_form( $PAGE->url );
$mForm = new local_webhooks_service_edit_form($PAGE->url);
$formData = (array) $mForm->get_data();
/* Cancel */
if ( $mForm->is_cancelled() ) {
redirect( $mainPage );
if ($mForm->is_cancelled()) {
redirect($mainPage);
}
/* Updating the data */
if ( !empty( $formData ) && confirm_sesskey() ) {
if ( isset( $formData[ "events" ] ) ) {
$formData[ "events" ] = array_keys( $formData[ "events" ] );
if (!empty($formData) && confirm_sesskey()) {
if (isset($formData['events'])) {
$formData['events'] = array_keys($formData['events']);
}
if ( !empty( $serviceId ) ) {
$formData[ "id" ] = $serviceId;
local_webhooks_api::update_service( $formData );
if (!empty($serviceId)) {
$formData['id'] = $serviceId;
local_webhooks_api::update_service($formData);
} else {
local_webhooks_api::create_service( $formData );
local_webhooks_api::create_service($formData);
}
redirect( $mainPage, new lang_string( "changessaved", "moodle" ) );
redirect($mainPage, new lang_string('changessaved', 'moodle'));
}
/* Loading service data */
if ( !empty( $serviceId ) ) {
$service = local_webhooks_api::get_service( $serviceId );
$service->events = array_fill_keys( $service->events, 1 );
$mForm->set_data( $service );
if (!empty($serviceId)) {
$service = local_webhooks_api::get_service($serviceId);
$service->events = array_fill_keys($service->events, 1);
$mForm->set_data($service);
}
/* The page title */
$titlePage = new lang_string( "externalservice", "webservice" );
$PAGE->navbar->add( $titlePage );
$PAGE->set_heading( $titlePage );
$PAGE->set_title( $titlePage );
$titlePage = new lang_string('externalservice', 'webservice');
$PAGE->navbar->add($titlePage);
$PAGE->set_heading($titlePage);
$PAGE->set_title($titlePage);
echo $OUTPUT->header();
/* Displays the form */

View File

@ -22,12 +22,16 @@
* @package local_webhooks
*/
defined( "MOODLE_INTERNAL" ) || die();
defined('MOODLE_INTERNAL') || die();
if ( $hassiteconfig ) {
$ADMIN->add( "server", new admin_externalpage( "local_webhooks",
new lang_string( "pluginname", "local_webhooks" ),
new moodle_url( "/local/webhooks/index.php" )
/* @var \admin_root $ADMIN */
if ($hassiteconfig) {
$ADMIN->add(
'server', new admin_externalpage(
'local_webhooks',
new lang_string('pluginname', 'local_webhooks'),
new moodle_url('/local/webhooks/index.php')
)
);
}

View File

@ -22,11 +22,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined("MOODLE_INTERNAL") || die();
defined('MOODLE_INTERNAL') || die();
$plugin->release = "4.0.0-rc.2 (Build: 2018022500)";
$plugin->version = 2018022500;
$plugin->requires = 2016112900;
$plugin->component = "local_webhooks";
$plugin->maturity = MATURITY_RC;
$plugin->dependencies = array("report_eventlist" => 2016120500);
$plugin->release = '4.0.0-rc.2 (Build: 2018022500)';
$plugin->version = 2018022500;
$plugin->requires = 2016112900;
$plugin->component = 'local_webhooks';
$plugin->maturity = MATURITY_RC;
$plugin->dependencies = array('report_eventlist' => 2016120500);