<?php
/**
* Server controller
*
* @author Mark Nielsen
* @version $Id$
* @package blocks/helloworld
*/
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
/**
* Default screen
*
* Demo of mr_server_rest
*/
public function view_action() {
global $CFG, $DB;
if (!$DB->record_exists('user', array('username' => 'administrator'))) {
$this->notify->add_string('For the service to work correctly, please create a user with username/password = administrator');
}
#### DEMO CODE ####
// Setup Zend
require_once 'Zend/Rest/Client.php';
// Lame-o
// Create a new HTTP client
$client = new Zend_Http_Client($https.'/blocks/helloworld/webservices.php');
// Set the post parameters that we want
$client->setParameterPost(array(
'token' => 'tokenvalue', // Part of security requirements, pass a token
'wsusername' => 'administrator', // Part of security requirements, pass username
'wspassword' => 'administrator', // Part of security requirements, pass password
'method' => 'test', // The service method to execute
'say' => 'Hello World!', // The service parameter name
));
// Send the request
$response = $client->request('POST');
$request = $client->getLastRequest();
// Dump the values
$output = $this->helper->dump($request, 'The sent request', true);
$output .= $this->helper->dump($response->getBody(), 'The returned response', true);
#### DEMO CODE ####
return $this->output->heading('Demo of mr_server_rest').
$this->helper->highlight(__CLASS__, __FUNCTION__, true).
$this->output->box($output, 'generalbox boxaligncenter boxwidthnormal');
}
}