ILIAS  release_8 Revision v8.24
Base.php
Go to the documentation of this file.
1<?php
20
21require_once('./webservice/soap/classes/class.ilSoapAdministration.php');
22require_once('./Services/WebServices/SOAP/classes/class.ilSoapPluginException.php');
23
24use ilOrgUnitSOAPServicesPlugin;
26use ilSoapMethod;
28
33abstract class Base extends ilSoapAdministration implements ilSoapMethod
34{
38 public const TYPE_INT_ARRAY = 'tns:intArray';
39 public const TYPE_STRING = 'xsd:string';
40 public const TYPE_INT = 'xsd:int';
41 public const TYPE_DOUBLE_ARRAY = 'tns:doubleArray';
42 public const SID = 'sid';
43 public const ORGU_REF_ID = 'orgu_ref_id';
44 public const POSITION_ID = 'position_id';
45 public const USR_IDS = 'usr_ids';
46 public const USR_ID = 'usr_id';
47
48 public function getServiceStyle(): string
49 {
50 return 'rpc';
51 }
52
53 public function getServiceUse(): string
54 {
55 return 'encoded';
56 }
57
65 protected function initIliasAndCheckSession(string $session_id): void
66 {
67 $this->initAuth($session_id);
68 $this->initIlias();
69 if (!$this->checkSession($session_id)) {
70 throw new ilSoapPluginException($this->getMessage());
71 }
72 }
73
79 protected function checkParameters(array $params): void
80 {
81 for ($i = 0, $iMax = count($this->getInputParams()); $i < $iMax; $i++) {
82 if (!isset($params[$i])) {
83 $names = implode(', ', array_keys($this->getInputParams()));
84 throw new ilSoapPluginException("Request is missing at least one of the following parameters: $names");
85 }
86 }
87 }
88
89 public function getServiceNamespace(): string
90 {
91 return 'urn:' . ilOrgUnitSOAPServicesPlugin::PLUGIN_NAME;
92 }
93
94 abstract protected function getAdditionalInputParams(): array;
95
96 public function getInputParams(): array
97 {
98 return array_merge(
99 array(
100 self::SID => self::TYPE_STRING,
101 ),
103 );
104 }
105
106 abstract protected function run(array $params);
107
108 public function execute(array $params)
109 {
110 $this->checkParameters($params);
111 $session_id = (isset($params[0])) ? $params[0] : '';
112 $this->init($session_id);
113
114 // Check Permissions
115 global $DIC;
116 if (!$DIC->access()->checkAccess('write', '', \ilObjOrgUnit::getRootOrgRefId())) {
117 $this->addError('Permission denied');
118 }
119
120 $clean_params = array();
121 $i = 1;
122 foreach ($this->getAdditionalInputParams() as $key => $type) {
123 $clean_params[$key] = $params[$i];
124 $i++;
125 }
126
127 return $this->run($clean_params);
128 }
129
133 public function addError(string $message)
134 {
135 throw $this->raiseError($message, 'ERROR');
136 }
137
141 private function init(string $session_id): void
142 {
143 $this->initIliasAndCheckSession($session_id); // Throws exception if session is not valid
144 }
145}
init(string $session_id)
Definition: Base.php:141
initIliasAndCheckSession(string $session_id)
Use this method at the beginning of your execute() method to check if the provided session ID is vali...
Definition: Base.php:65
getInputParams()
Get the input parameters.
Definition: Base.php:96
checkParameters(array $params)
Check that all input parameters are present when executing the soap method.
Definition: Base.php:79
getServiceStyle()
Get the service style, e.g.
Definition: Base.php:48
getServiceNamespace()
Get the namespace of the service where this method belongs to.
Definition: Base.php:89
execute(array $params)
Execute the business logic for this SOAP method (when a SOAP request hits the endpoint defined by the...
Definition: Base.php:108
getServiceUse()
Get the service use, e.g.
Definition: Base.php:53
static getRootOrgRefId()
soap server Base class for all SOAP registered methods.
raiseError(string $a_message, $a_code)
Class ilSoapPluginException.
global $DIC
Definition: feed.php:28
Interface ilSoapMethod.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
$i
Definition: metadata.php:41
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type