ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSCourseConnector.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php';
5 include_once './Services/WebServices/ECS/classes/class.ilECSConnectorException.php';
6 
14 {
15 
20  public function __construct(ilECSSetting $settings = null)
21  {
23  }
24 
25 
30  public function getCourse($course_id,$a_details = false)
31  {
32  $this->path_postfix = '/campusconnect/courses/'. (int) $course_id;
33 
34  if($a_details and $course_id)
35  {
36  $this->path_postfix .= '/details';
37  }
38 
39  try {
40  $this->prepareConnection();
41  $this->setHeader(array());
42  if($a_details)
43  {
44  $this->addHeader('Accept', 'application/json');
45  }
46  else
47  {
48  $this->addHeader('Accept', 'text/uri-list');
49  }
50  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
51  $res = $this->call();
52 
53  if(substr($res, 0, 4) == 'http')
54  {
55  $json = file_get_contents($res);
56  $ecs_result = new ilECSResult($json);
57  }
58  else
59  {
60  $ecs_result = new ilECSResult($res);
61 
62  }
63 
64  // Return ECSEContentDetails for details switch
65  if($a_details)
66  {
67  include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
68  $details = new ilECSEContentDetails();
69  $details->loadFromJson($ecs_result->getResult());
70  return $details;
71  }
72  // Return json result
73  return $ecs_result->getResult();
74  }
75  catch(ilCurlConnectionException $e)
76  {
77  throw new ilECSConnectorException('Error calling ECS service: '.$e->getMessage());
78  }
79  }
80 }
81 ?>