ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Base.php
Go to the documentation of this file.
1 <?php
20 
21 require_once('./webservice/soap/classes/class.ilSoapAdministration.php');
22 require_once('./Services/WebServices/SOAP/classes/class.ilSoapPluginException.php');
23 
26 use ilSoapMethod;
28 
33 abstract 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  protected \ilOrgUnitPositionDBRepository $positionRepo;
48  protected \ilOrgUnitUserAssignmentDBRepository $assignmentRepo;
49 
50  public function getServiceStyle(): string
51  {
52  return 'rpc';
53  }
54 
55  public function getServiceUse(): string
56  {
57  return 'encoded';
58  }
59 
67  protected function initIliasAndCheckSession(string $session_id): void
68  {
69  $this->initAuth($session_id);
70  $this->initIlias();
71  if (!$this->checkSession($session_id)) {
72  throw new ilSoapPluginException($this->getMessage());
73  }
74  }
75 
81  protected function checkParameters(array $params): void
82  {
83  for ($i = 0, $iMax = count($this->getInputParams()); $i < $iMax; $i++) {
84  if (!isset($params[$i])) {
85  $names = implode(', ', array_keys($this->getInputParams()));
86  throw new ilSoapPluginException("Request is missing at least one of the following parameters: $names");
87  }
88  }
89  }
90 
91  public function getServiceNamespace(): string
92  {
93  return 'urn:' . ilOrgUnitSOAPServicesPlugin::PLUGIN_NAME;
94  }
95 
96  abstract protected function getAdditionalInputParams(): array;
97 
98  public function getInputParams(): array
99  {
100  return array_merge(
101  array(
102  self::SID => self::TYPE_STRING,
103  ),
104  $this->getAdditionalInputParams()
105  );
106  }
107 
108  abstract protected function run(array $params);
109 
110  public function execute(array $params)
111  {
112  $this->checkParameters($params);
113  $session_id = (isset($params[0])) ? $params[0] : '';
114  $this->init($session_id);
115 
116  // Check Permissions
117  global $DIC;
118  if (!$DIC->access()->checkAccess('write', '', \ilObjOrgUnit::getRootOrgRefId())) {
119  $this->addError('Permission denied');
120  }
121 
122  $clean_params = array();
123  $i = 1;
124  foreach ($this->getAdditionalInputParams() as $key => $type) {
125  $clean_params[$key] = $params[$i];
126  $i++;
127  }
128 
129  return $this->run($clean_params);
130  }
131 
135  public function addError(string $message)
136  {
137  throw $this->raiseError($message, 'ERROR');
138  }
139 
143  private function init(string $session_id): void
144  {
145  $this->initIliasAndCheckSession($session_id); // Throws exception if session is not valid
146 
147  if (!isset($_GET["wsdl"])) {
149  $this->positionRepo = $dic["repo.Positions"];
150  $this->assignmentRepo = $dic["repo.UserAssignments"];
151  }
152  }
153 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$_GET["client_id"]
Definition: webdav.php:30
execute(array $params)
Execute the business logic for this SOAP method (when a SOAP request hits the endpoint defined by the...
Definition: Base.php:110
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
ilOrgUnitUserAssignmentDBRepository $assignmentRepo
Definition: Base.php:48
raiseError(string $a_message, $a_code)
init(string $session_id)
Definition: Base.php:143
getServiceUse()
Get the service use, e.g.
Definition: Base.php:55
getInputParams()
Get the input parameters.
Definition: Base.php:98
global $DIC
Definition: feed.php:28
string $key
Consumer key/client ID value.
Definition: System.php:193
static getRootOrgRefId()
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:67
$dic
Definition: result.php:32
checkParameters(array $params)
Check that all input parameters are present when executing the soap method.
Definition: Base.php:81
getServiceStyle()
Get the service style, e.g.
Definition: Base.php:50
getServiceNamespace()
Get the namespace of the service where this method belongs to.
Definition: Base.php:91
ilOrgUnitPositionDBRepository $positionRepo
Definition: Base.php:47