webservice MDL-21658 add moodle_user_delete_users() unit test function + fix moodle_u...
[moodle.git] / webservice / soap / lib.php
CommitLineData
75681c41 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18require_once 'Zend/Soap/Client.php';
19
20/**
21 * Moodle SOAP client class
22 */
23class webservice_soap_client extends Zend_Soap_Client {
24
25 private $serverurl;
26
27 /**
28 * Constructor
29 * @param string $serverurl
30 * @param string $token
d1d0788d 31 * @param array $options PHP SOAP client options - see php.net
75681c41 32 */
d1d0788d 33 public function __construct($serverurl, $token, $options = null) {
75681c41 34 $this->serverurl = $serverurl;
35 $wsdl = $serverurl . "?wstoken=" . $token . '&wsdl=1';
d1d0788d 36 parent::__construct($wsdl, $options);
75681c41 37 }
38
39 /**
40 * Set the token used to do the SOAP call
41 * @param string $token
42 */
43 public function set_token($token) {
44 $wsdl = $this->serverurl . "?wstoken=" . $token . '&wsdl=1';
45 $this->setWsdl($wsdl);
46 }
47
48 /**
49 * Execute client WS request
50 * @param string $functionname
51 * @param array $params
52 * @return mixed
53 */
54 public function call($functionname, $params) {
55 global $DB, $CFG;
56
57 //zend expects 0 based array with numeric indexes
58 $params = array_values($params);
59
60 //traditional Zend soap client call (integrating the token into the URL)
61 $result = $this->__call($functionname, $params);
62
63 return $result;
64 }
65
66}