Browse Source

Criado bloco de eventos de cursos

master
eduardo 6 years ago
commit
331a72f47a
  1. 21
      block_courses_verification.php
  2. BIN
      classes/httpful.phar
  3. 23
      classes/observer.php
  4. 26
      db/access.php
  5. 11
      db/events.php
  6. 3
      lang/en/block_courses_verification.php
  7. 4
      version.php

21
block_courses_verification.php

@ -0,0 +1,21 @@
<?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;
}
}

BIN
classes/httpful.phar

Binary file not shown.

23
classes/observer.php

@ -0,0 +1,23 @@
<?php
include('httpful.phar');
class block_courses_verification_observer {
public static function 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/add_course/';
$response = \Httpful\Request::post($uri)
->sendsJson()
->body('{"course":{"name":"' . $dados->fullname . '"}}') // o json é {"curso":{"nome":"nome_curso"}}
->send();
}
public static function updated(\core\event\base $event) {
global $DB, $CFG;
$dados = new stdClass();
$dados->article_title='TesteCurso';
$dados->article_text='TesteCurso';
$DB->insert_record('block_article', $dados);
}
}

26
db/access.php

@ -0,0 +1,26 @@
<?php
$capabilities = array(
'block/courses_verification:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/courses_verification:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);

11
db/events.php

@ -0,0 +1,11 @@
<?php
$observers = array(
array(
'eventname' => '\core\event\course_created',
'callback' => 'block_courses_verification_observer::created'
),
array(
'eventname' => '\core\event\course_updated',
'callback' => 'block_courses_verification_observer::updated',
)
);

3
lang/en/block_courses_verification.php

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

4
version.php

@ -0,0 +1,4 @@
<?php
$plugin->version = 2018061801;
$plugin->requires = 2017110800;
$plugin->component = 'block_courses_verification';
Loading…
Cancel
Save