ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilECSResult.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('./Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
25 
36 {
37  const RESULT_TYPE_JSON = 1;
39 
40  protected $log;
41 
42  protected $result_string = '';
43  protected $http_code = '';
44  protected $result;
45  protected $result_type;
46 
47  protected $headers = array();
48 
58  public function __construct($a_res, $a_type = self::RESULT_TYPE_JSON)
59  {
60  global $DIC;
61 
62  $ilLog = $DIC['ilLog'];
63 
64  $this->log = $ilLog;
65 
66  $this->result_string = $a_res;
67  $this->result_type = $a_type;
68 
69  $this->init();
70  }
71 
79  public function setHTTPCode($a_code)
80  {
81  $this->http_code = $a_code;
82  }
83 
89  public function getHTTPCode()
90  {
91  return $this->http_code;
92  }
93 
100  public function getPlainResultString()
101  {
102  return $this->result_string;
103  }
104 
112  public function getResult()
113  {
114  return $this->result;
115  }
116 
121  public function setHeaders($a_headers)
122  {
123  $this->headers = $a_headers;
124  }
125 
131  public function getHeaders()
132  {
133  return $this->headers ?: [];
134  }
135 
141  private function init()
142  {
143  switch ($this->result_type) {
144  case self::RESULT_TYPE_JSON:
145  if ($this->result_string) {
146  $this->result = json_decode($this->result_string);
147  } else {
148  $this->result = array();
149  }
150  break;
151 
152  case self::RESULT_TYPE_URL_LIST:
153  $this->result = $this->parseUriList($this->result_string);
154  break;
155  }
156  return true;
157  }
158 
164  private function parseUriList($a_content)
165  {
166  include_once 'Services/WebServices/ECS/classes/class.ilECSUriList.php';
167  $list = new ilECSUriList();
168  $lines = explode("\n", $this->getPlainResultString());
169  foreach ($lines as $line) {
170  $line = trim($line);
171  if (!strlen($line)) {
172  continue;
173  }
174  $uri_parts = explode("/", $line);
175  $list->add($line, array_pop($uri_parts));
176  }
177 
178  return $list;
179  }
180 }
const RESULT_TYPE_URL_LIST
Presentation of ecs uril (http://...campusconnect/courselinks)
getResult()
get result
setHeaders($a_headers)
Set header.
getPlainResultString()
get unformated result string
setHTTPCode($a_code)
set HTTP return code
global $DIC
Definition: goto.php:24
__construct($a_res, $a_type=self::RESULT_TYPE_JSON)
Constructor.
parseUriList($a_content)
getHTTPCode()
get HTTP code
init()
init result (json_decode) private
getHeaders()
get headers