diff options
author | Valentin Popov <info@valentineus.link> | 2018-10-22 01:17:12 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2018-10-22 01:59:06 +0300 |
commit | 1352b5ee796c9a9e106cb9746b9201e8038b6210 (patch) | |
tree | c922ed9bacd8b2ac0d278cb44697ade9124b380f /classes | |
parent | f3b5ab561616ce42c5ddff11b632635a1c71f88f (diff) | |
download | local_webhooks-1352b5ee796c9a9e106cb9746b9201e8038b6210.tar.xz local_webhooks-1352b5ee796c9a9e106cb9746b9201e8038b6210.zip |
Code style fix
Signed-off-by: Valentin Popov <info@valentineus.link>
Diffstat (limited to 'classes')
-rw-r--r-- | classes/event_observer.php | 8 | ||||
-rw-r--r-- | classes/task/process_events_task.php | 25 | ||||
-rw-r--r-- | classes/ui_forms_plugin.php | 66 | ||||
-rw-r--r-- | classes/ui_tables_plugin.php | 95 |
4 files changed, 106 insertions, 88 deletions
diff --git a/classes/event_observer.php b/classes/event_observer.php index 9ab4a35..983552a 100644 --- a/classes/event_observer.php +++ b/classes/event_observer.php @@ -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); } }
\ No newline at end of file diff --git a/classes/task/process_events_task.php b/classes/task/process_events_task.php index 84b5c88..02e54a2 100644 --- a/classes/task/process_events_task.php +++ b/classes/task/process_events_task.php @@ -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; - - require_once( $CFG->dirroot . "/local/webhooks/lib.php" ); - - $services = \local_webhooks_api::get_services_by_event( $this->get_custom_data()->eventname ); + $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(); diff --git a/classes/ui_forms_plugin.php b/classes/ui_forms_plugin.php index 2cd7541..6c9a070 100644 --- a/classes/ui_forms_plugin.php +++ b/classes/ui_forms_plugin.php @@ -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); } -} +}
\ No newline at end of file diff --git a/classes/ui_tables_plugin.php b/classes/ui_tables_plugin.php index 7e39598..ecc0c52 100644 --- a/classes/ui_tables_plugin.php +++ b/classes/ui_tables_plugin.php @@ -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); } }
\ No newline at end of file |