Correction of implicit style errors

Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
Valentin Popov 2018-10-22 03:14:31 +04:00
parent 14e5a16a33
commit 99c835a63d
Signed by: Valentin Popov
GPG Key ID: 269A00ACA90A8EA3
8 changed files with 153 additions and 150 deletions

View File

@ -24,11 +24,11 @@
namespace local_webhooks\task;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once $CFG->dirroot . '/local/webhooks/lib.php';
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/local/webhooks/lib.php');
/**
* Class process_events_task
@ -60,7 +60,8 @@ class process_events_task extends \core\task\adhoc_task {
$curl->setHeader(array('Content-Type: ' . $service->header));
$curl->post($service->point, json_encode($event));
// TODO: Mark the log
// TODO: Mark the log.
$curl->getResponse();
}
}

View File

@ -24,8 +24,8 @@
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.
@ -36,10 +36,10 @@ require_once $CFG->libdir . '/formslib.php';
*/
class local_webhooks_service_edit_form extends moodleform {
/**
* @param string $baseUrl
* @param string $base_url
*/
public function __construct($baseUrl) {
parent::__construct($baseUrl);
public function __construct($base_url) {
parent::__construct($base_url);
}
/**
@ -48,55 +48,55 @@ class local_webhooks_service_edit_form extends moodleform {
* @throws \coding_exception
*/
protected function definition() {
$mForm =& $this->_form;
$m_form =& $this->_form;
$size = array('size' => 60);
/* Form heading */
$mForm->addElement('header', 'editserviceheadermain', new lang_string('service', 'webservice'));
$m_form->addElement('header', 'edit-service-header-main', 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);
$m_form->addElement('text', 'name', new lang_string('name', 'moodle'), $size);
$m_form->addRule('name', null, 'required');
$m_form->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);
$m_form->addElement('text', 'point', new lang_string('url', 'moodle'), $size);
$m_form->addRule('point', null, 'required');
$m_form->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');
$m_form->addElement('advcheckbox', 'status', new lang_string('enable', 'moodle'));
$m_form->setType('status', PARAM_BOOL);
$m_form->setDefault('status', 1);
$m_form->setAdvanced('status');
/* Token */
$mForm->addElement('text', 'token', new lang_string('token', 'webservice'), $size);
$mForm->addRule('token', null, 'required');
$mForm->setType('token', PARAM_RAW);
$m_form->addElement('text', 'token', new lang_string('token', 'webservice'), $size);
$m_form->addRule('token', null, 'required');
$m_form->setType('token', PARAM_RAW);
/* Content type */
$contentType = array(
$content_type = array(
'application/json' => 'application/json',
'application/x-www-form-urlencoded' => 'application/x-www-form-urlencoded',
);
$mForm->addElement('select', 'header', 'Content-Type', $contentType);
$mForm->setAdvanced('header');
$m_form->addElement('select', 'header', 'Content-Type', $content_type);
$m_form->setAdvanced('header');
/* Form heading */
$mForm->addElement('header', 'editserviceheaderevent', new lang_string('edulevel', 'moodle'));
$m_form->addElement('header', 'edit-service-header-event', new lang_string('edulevel', 'moodle'));
/* List of events */
$eventList = report_eventlist_list_generator::get_all_events_list(true);
$event_list = 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 ($event_list as $event) {
$events[$event['component']][] =& $m_form->createElement('checkbox', $event['eventname'], $event['eventname']);
}
foreach ($events as $key => $event) {
$mForm->addGroup($event, 'events', $key, '<br />', true);
$m_form->addGroup($event, 'events', $key, '<br />', true);
}
/* Control Panel */

View File

@ -24,8 +24,8 @@
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.
@ -36,24 +36,24 @@ require_once $CFG->libdir . '/tablelib.php';
*/
class local_webhooks_services_table extends table_sql {
/**
* @var string $mainPage
* @var string $main_page
*/
protected static $mainPage = '/local/webhooks/index.php';
protected static $main_page = '/local/webhooks/index.php';
/**
* @var string $editorPage
* @var string $editor_page
*/
protected static $editorPage = '/local/webhooks/service.php';
protected static $editor_page = '/local/webhooks/service.php';
/**
* Constructor.
*
* @param string $uniqueId
* @param string $unique_id
*
* @throws \coding_exception
*/
public function __construct($uniqueId = '') {
parent::__construct($uniqueId);
public function __construct($unique_id = '') {
parent::__construct($unique_id);
$this->define_table_columns();
$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.
*
* @param int $pageSize
* @param boolean $useInitialsBar
* @param int $page_size
* @param boolean $use_initials_bar
*
* @throws \dml_exception
*/
public function query_db($pageSize = 0, $useInitialsBar = false) {
public function query_db($page_size = 0, $use_initials_bar = false) {
$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) {
global $OUTPUT;
$hideShowIcon = 't/show';
$hideShowString = new lang_string('enable', 'moodle');
$hide_show_icon = 't/show';
$hide_show_string = new lang_string('enable', 'moodle');
if (!empty($row->status)) {
$hideShowIcon = 't/hide';
$hideShowString = new lang_string('disable', 'moodle');
$hide_show_icon = 't/hide';
$hide_show_string = 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));
$hide_show_link = new moodle_url(self::$main_page, array('hideshowid' => $row->id, 'sesskey' => sesskey()));
$hide_show_item = $OUTPUT->action_icon($hide_show_link, new pix_icon($hide_show_icon, $hide_show_string));
/* 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')));
$edit_link = new moodle_url(self::$editor_page, array('serviceid' => $row->id, 'sesskey' => sesskey()));
$edit_item = $OUTPUT->action_icon($edit_link, 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')));
$delete_link = new moodle_url(self::$main_page, array('deleteid' => $row->id, 'sesskey' => sesskey()));
$delete_item = $OUTPUT->action_icon($delete_link, new pix_icon('t/delete', new lang_string('delete', 'moodle')));
return $hideShowItem . $editItem . $deleteItem;
return $hide_show_item . $edit_item . $delete_item;
}
/**
@ -159,7 +159,7 @@ class local_webhooks_services_table extends table_sql {
* @throws \moodle_exception
*/
public function col_name($row) {
$link = new moodle_url(self::$editorPage, array('serviceid' => $row->id, 'sesskey' => sesskey()));
$link = new moodle_url(self::$editor_page, array('serviceid' => $row->id, 'sesskey' => sesskey()));
return html_writer::link($link, $row->name);
}

View File

@ -27,41 +27,43 @@ defined('MOODLE_INTERNAL') || die();
/**
* Function to upgrade 'local_webhooks'.
*
* @param int $oldversion
* @param int $old_version
*
* @return boolean
* @throws \dml_exception
* @throws \downgrade_exception
* @throws \upgrade_exception
*/
function xmldb_local_webhooks_upgrade($oldversion = 0) {
function xmldb_local_webhooks_upgrade($old_version = 0) {
global $DB;
/* Update from versions 3.* */
if ($oldversion < 2017112600 || $oldversion === 2018061900) {
if ($old_version < 2017112600 || $old_version === 2018061900) {
$rs = $DB->get_recordset('local_webhooks_service', null, 'id', '*', 0, 0);
foreach ($rs as $record) {
if (!empty($record->events)) {
$record->events = unserialize(gzuncompress(base64_decode($record->events)));
// TODO: This method does not exist
// local_webhooks_update_record( $record );
// TODO: This method does not exist.
/* local_webhooks_update_record( $record ); */
}
}
$rs->close();
upgrade_plugin_savepoint(true, 2017112600, 'local', 'webhooks');
}
/* Update from version 4.0.0-rc.1 */
if ($oldversion === 2017122900) {
}
/* if ($old_version === 2017122900) {} */
/* Update from version 4.0.0-rc.2 */
if ($oldversion === 2018022200) {
}
/* if ($old_version === 2018022200) {} */
/* Update from version 4.0.0-rc.3 */
if ($oldversion === 2018022500) {
}
/* if ($old_version === 2018022500) {} */
return true;
}

View File

@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
require_once $CFG->libdir . '/externallib.php';
require_once($CFG->libdir . '/externallib.php');
/**
* External functions.

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);
$delete_id = optional_param('deleteid', 0, PARAM_INT);
$hide_show_id = optional_param('hideshowid', 0, PARAM_INT);
$editPage = '/local/webhooks/service.php';
$mainPage = '/local/webhooks/index.php';
$baseUrl = new moodle_url($mainPage);
$edit_page = '/local/webhooks/service.php';
$main_page = '/local/webhooks/index.php';
$base_url = new moodle_url($main_page);
admin_externalpage_setup('local_webhooks', '', null, $baseUrl, array());
admin_externalpage_setup('local_webhooks', '', null, $base_url, array());
$context = context_system::instance();
/* Remove the service */
if (!empty($deleteId) && confirm_sesskey()) {
local_webhooks_api::delete_service($deleteId);
if (!empty($delete_id) && confirm_sesskey()) {
local_webhooks_api::delete_service($delete_id);
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($hide_show_id) && confirm_sesskey()) {
$service = local_webhooks_api::get_service($hide_show_id);
$service->status = !(bool) $service->status;
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);
$title_page = new lang_string('pluginname', 'local_webhooks');
$PAGE->set_heading($title_page);
$PAGE->set_title($title_page);
echo $OUTPUT->header();
/* Displays the table */
$table = new local_webhooks_services_table('local-webhooks-table');
$table->define_baseurl($baseUrl);
$table->define_baseurl($base_url);
$table->out(25, true);
/* Separation */
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'));
$add_service_url = new moodle_url($edit_page, array('sesskey' => sesskey()));
echo $OUTPUT->single_button($add_service_url, new lang_string('add', 'moodle'));
/* Footer */
echo $OUTPUT->footer();

66
lib.php
View File

@ -38,21 +38,21 @@ class local_webhooks_api {
/**
* Get information about the service.
*
* @param int $serviceId
* @param int $service_id
*
* @return object
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function get_service($serviceId = 0) {
public static function get_service($service_id = 0) {
global $DB;
if (!is_numeric($serviceId) || $serviceId === 0) {
print_error('unknowparamtype', 'error', null, 'serviceId');
if (!is_numeric($service_id) || $service_id === 0) {
print_error('unknowparamtype', 'error', null, 'service_id');
}
$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' => $service_id), '*', MUST_EXIST);
$events = $DB->get_records(LW_TABLE_EVENTS, array('serviceid' => $service_id), '', '*', 0, 0);
$service->events = array();
foreach ($events as $event) {
@ -67,16 +67,16 @@ class local_webhooks_api {
* By default, the entire list of services is given.
*
* @param array $conditions
* @param int $limitFrom
* @param int $limitNum
* @param int $limit_from
* @param int $limit_num
*
* @return array
* @throws \dml_exception
*/
public static function get_services(array $conditions = array(), $limitFrom = 0, $limitNum = 0) {
public static function get_services(array $conditions = array(), $limit_from = 0, $limit_num = 0) {
global $DB;
$services = $DB->get_records(LW_TABLE_SERVICES, $conditions, '', '*', $limitFrom, $limitNum);
$services = $DB->get_records(LW_TABLE_SERVICES, $conditions, '', '*', $limit_from, $limit_num);
foreach ($services as $service) {
$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.
*
* @param string $eventName
* @param string $event_name
*
* @return array
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function get_services_by_event($eventName = '') {
public static function get_services_by_event($event_name = '') {
global $DB;
if (!is_string($eventName) || $eventName === '') {
print_error('unknowparamtype', 'error', null, 'eventName');
if (!is_string($event_name) || $event_name === '') {
print_error('unknowparamtype', 'error', null, 'event_name');
}
$events = $DB->get_records(LW_TABLE_EVENTS, array('name' => $eventName), '', '*', 0, 0);
$events = $DB->get_records(LW_TABLE_EVENTS, array('name' => $event_name), '', '*', 0, 0);
$services = array();
foreach ($events as $event) {
@ -132,37 +132,37 @@ class local_webhooks_api {
print_error('unknowparamtype', 'error', null, 'service');
}
$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);
$service_id = $DB->insert_record(LW_TABLE_SERVICES, (object) $service, true, false);
if ($service_id && !empty($service['events']) && is_array($service['events'])) {
self::insert_events($service['events'], $service_id);
}
// TODO: Mark the log
// TODO: Mark the log.
return (int) $serviceId;
return (int) $service_id;
}
/**
* Delete the service data from the database.
*
* @param int $serviceId
* @param int $service_id
*
* @return bool
* @throws \dml_exception
* @throws \moodle_exception
*/
public static function delete_service($serviceId = 0) {
public static function delete_service($service_id = 0) {
global $DB;
if (!is_numeric($serviceId) || $serviceId === 0) {
print_error('unknowparamtype', 'error', null, 'serviceId');
if (!is_numeric($service_id) || $service_id === 0) {
print_error('unknowparamtype', 'error', null, 'service_id');
}
// TODO: Mark the log
// TODO: Mark the log.
$DB->delete_records(LW_TABLE_EVENTS, array('serviceid' => $serviceId));
$DB->delete_records(LW_TABLE_EVENTS, array('serviceid' => $service_id));
return $DB->delete_records(LW_TABLE_SERVICES, array('id' => $serviceId));
return $DB->delete_records(LW_TABLE_SERVICES, array('id' => $service_id));
}
/**
@ -181,7 +181,7 @@ class local_webhooks_api {
print_error('unknowparamtype', 'error', null, 'service');
}
// TODO: Add transactions for operations
// TODO: Add transactions for operations.
$result = $DB->update_record(LW_TABLE_SERVICES, (object) $service, false);
$DB->delete_records(LW_TABLE_EVENTS, array('serviceid' => $service['id']));
@ -189,7 +189,7 @@ class local_webhooks_api {
self::insert_events($service['events'], $service['id']);
}
// TODO: Mark the log
// TODO: Mark the log.
return $result;
}
@ -198,17 +198,17 @@ class local_webhooks_api {
* Save the list of events to the database.
*
* @param array $events
* @param int $serviceId
* @param int $service_id
*
* @throws \coding_exception
* @throws \dml_exception
*/
protected static function insert_events(array $events = array(), $serviceId = 0) {
protected static function insert_events(array $events = array(), $service_id = 0) {
global $DB;
$conditions = array();
foreach ($events as $eventName) {
$conditions[] = array('name' => $eventName, 'serviceid' => $serviceId);
foreach ($events as $event_name) {
$conditions[] = array('name' => $event_name, 'serviceid' => $service_id);
}
$DB->insert_records(LW_TABLE_EVENTS, $conditions);

View File

@ -22,61 +22,61 @@
* @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);
$service_id = 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');
$url_parameters = array('serviceid' => $service_id);
$base_url = new moodle_url('/local/webhooks/service.php', $url_parameters);
$main_page = new moodle_url('/local/webhooks/index.php');
admin_externalpage_setup('local_webhooks', '', null, $baseUrl, array());
admin_externalpage_setup('local_webhooks', '', null, $base_url, array());
$context = context_system::instance();
$mForm = new local_webhooks_service_edit_form($PAGE->url);
$formData = (array) $mForm->get_data();
$m_form = new local_webhooks_service_edit_form($PAGE->url);
$form_data = (array) $m_form->get_data();
/* Cancel */
if ($mForm->is_cancelled()) {
redirect($mainPage);
if ($m_form->is_cancelled()) {
redirect($main_page);
}
/* Updating the data */
if (!empty($formData) && confirm_sesskey()) {
if (isset($formData['events'])) {
$formData['events'] = array_keys($formData['events']);
if (!empty($form_data) && confirm_sesskey()) {
if (isset($form_data['events'])) {
$form_data['events'] = array_keys($form_data['events']);
}
if (!empty($serviceId)) {
$formData['id'] = $serviceId;
local_webhooks_api::update_service($formData);
if (!empty($service_id)) {
$form_data['id'] = $service_id;
local_webhooks_api::update_service($form_data);
} else {
local_webhooks_api::create_service($formData);
local_webhooks_api::create_service($form_data);
}
redirect($mainPage, new lang_string('changessaved', 'moodle'));
redirect($main_page, new lang_string('changessaved', 'moodle'));
}
/* Loading service data */
if (!empty($serviceId)) {
$service = local_webhooks_api::get_service($serviceId);
if (!empty($service_id)) {
$service = local_webhooks_api::get_service($service_id);
$service->events = array_fill_keys($service->events, 1);
$mForm->set_data($service);
$m_form->set_data($service);
}
/* The page title */
$titlePage = new lang_string('externalservice', 'webservice');
$PAGE->navbar->add($titlePage);
$PAGE->set_heading($titlePage);
$PAGE->set_title($titlePage);
$title_page = new lang_string('externalservice', 'webservice');
$PAGE->navbar->add($title_page);
$PAGE->set_heading($title_page);
$PAGE->set_title($title_page);
echo $OUTPUT->header();
/* Displays the form */
$mForm->display();
$m_form->display();
/* Footer */
echo $OUTPUT->footer();