Browse Source

Início de desenvolvimento do plugin

master
Matheus Garcia 6 years ago
parent
commit
fdb4a434bd
  1. 21
      block_courses_verification.php
  2. 19
      block_escola_modelo.php
  3. 42
      classes/observer.php
  4. 6
      db/access.php
  5. 24
      db/events.php
  6. 3
      lang/en/block_courses_verification.php
  7. 3
      lang/en/block_escola_modelo.php
  8. 2
      version.php

21
block_courses_verification.php

@ -1,21 +0,0 @@
<?php
defined('MOODLE_INTERNAL') || die();
class block_courses_verification extends block_base
{
public function init() {
$this->title = get_string('courses_verification', 'block_courses_verification');
}
public function get_content() {
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = 'The content of our block!';
//$url = new moodle_url('/blocks/article/new.php');
//$url_index = new moodle_url('/blocks/article/index.php');
return $this->content;
}
}

19
block_escola_modelo.php

@ -0,0 +1,19 @@
<?php
defined('MOODLE_INTERNAL') || die();
class block_escola_modelo extends block_base
{
public function init() {
$this->title = get_string('escola_modelo', 'block_escola_modelo');
}
public function get_content() {
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = '';
return $this->content;
}
}

42
classes/observer.php

@ -2,8 +2,13 @@
include('httpful.phar');
class block_courses_verification_observer {
public static function created(\core\event\base $event) {
class block_escola_modelo_observer {
//
// EVENTOS RELACIONADOS A CURSOS
//
public static function course_created(\core\event\base $event) {
global $DB, $CFG;
$dados = $DB->get_record($event->objecttable,array('id'=>$event->objectid));
$uri = 'http://localhost:3000/api/v1/courses/adicionar/';
@ -13,20 +18,39 @@ class block_courses_verification_observer {
->send();
}
public static function updated(\core\event\base $event) {
public static function course_updated(\core\event\base $event) {
global $DB, $CFG;
$dados = $DB->get_record($event->objecttable,array('id'=>$event->objectid));
$uri = 'http://localhost:3000/api/v1/courses/atualizar/';
//echo "ID é " . $dados->id;
$uri = 'https://escolamodelows.interlegis.leg.br/api/v1/cursos/atualizar';
$response = \Httpful\Request::patch($uri)
->sendsJson()
->body('{"course":{
"id":"1",
"name":"' . $dados->fullname . '",
"course_category_id":"' . "1" . '",
"ead_id":"' . $dados->id . '",
"school_id":"' . "1" . '",
"description:"' . $dados->summary . '"
"course_category_id":"' . "1" . '"
}
}') // o json é {"curso":{"nome":"nome_curso"}}
->send();
error_log("Retorno é " . $response->code);
}
public static function course_deleted(\core\event\base $event) {
}
}
//
// EVENTOS RELACIONADOS A MATRÍCULAS
//
//public static function course_updated(\core\event\base $event) {
//}
}

6
db/access.php

@ -1,7 +1,7 @@
<?php
$capabilities = array(
'block/courses_verification:myaddinstance' => array(
'block/escola_modelo:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
@ -11,7 +11,7 @@ $capabilities = array(
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/courses_verification:addinstance' => array(
'block/escola_modelo:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
@ -23,4 +23,4 @@ $capabilities = array(
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
);

24
db/events.php

@ -1,11 +1,29 @@
<?php
$observers = array(
// Eventos de cursos
array(
'eventname' => '\core\event\course_created',
'callback' => 'block_courses_verification_observer::created'
'callback' => 'block_escola_modelo_observer::course_created'
),
array(
'eventname' => '\core\event\course_updated',
'callback' => 'block_courses_verification_observer::updated',
'callback' => 'block_escola_modelo_observer::course_updated'
),
array(
'eventname' => '\core\event\course_deleted',
'callback' => 'block_escola_modelo_observer::course_deleted'
),
// Eventos de matrícula a cursos
array(
'eventname' => 'core\event\user_enrolment_created',
'callback' => 'block_escola_modelo_observer::user_enrolment_created'
),
array(
'eventname' => 'core\event\user_enrolment_deleted',
'callback' => 'block_escola_modelo_observer::user_enrolment_deleted'
),
array(
'eventname' => 'core\event\user_enrolment_updated',
'callback' => 'block_escola_modelo_observer::user_enrolment_updated'
)
);
);

3
lang/en/block_courses_verification.php

@ -1,3 +0,0 @@
<?php
$string['pluginname'] = 'Bloco de verificação de criação de cursos';
$string['courses_verification'] = 'Verificação de criação de cursos';

3
lang/en/block_escola_modelo.php

@ -0,0 +1,3 @@
<?php
$string['pluginname'] = 'Bloco para Escola Modelo';
$string['escola_modelo'] = 'Customizações para Escola Modelo';

2
version.php

@ -1,4 +1,4 @@
<?php
$plugin->version = 2018061801;
$plugin->requires = 2017110800;
$plugin->component = 'block_courses_verification';
$plugin->component = 'block_escola_modelo';

Loading…
Cancel
Save