ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSEContentReader.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 
33 {
34  protected $log;
35  protected $settings = null;
36  protected $connector = null;
37 
38  protected $econtent = array();
39  protected $econtent_id = 0;
40 
47  public function __construct($a_econtent_id = 0)
48  {
49  global $ilLog;
50 
51  include_once('Services/WebServices/ECS/classes/class.ilECSSettings.php');
52  include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
53  include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
54  include_once('Services/WebServices/ECS/classes/class.ilECSEContent.php');
55  include_once('Services/WebServices/ECS/classes/class.ilECSReaderException.php');
56 
57  $this->settings = ilECSSettings::_getInstance();
58  $this->connector = new ilECSConnector();
59  $this->log = $ilLog;
60 
61  $this->econtent_id = $a_econtent_id;
62  }
63 
70  public function getEContent()
71  {
72  return $this->econtent ? $this->econtent : array();
73  }
74 
82  public function read()
83  {
84  global $ilLog;
85 
86  try
87  {
88  $res = $this->connector->getResources($this->econtent_id);
89 
90  if($res->getHTTPCode() == ilECSConnector::HTTP_CODE_NOT_FOUND)
91  {
92  return false;
93  }
94 
95  if(!is_array($res->getResult()))
96  {
97  $ilLog->write(__METHOD__.': Error parsing result. Expected result of type array.');
98  throw new ilECSReaderException('Error parsing query');
99  }
100  foreach($res->getResult() as $econtent)
101  {
102  $tmp_content = new ilECSEContent();
103  $tmp_content->loadFromJSON($econtent);
104 
105  $this->econtent[] = $tmp_content;
106  }
107  return true;
108  }
109  catch(ilECSConnectorException $e)
110  {
111  $ilLog->write(__METHOD__.': Error connecting to ECS server. '.$e->getMessage());
112  throw $e;
113  }
114  catch(ilECSReaderException $e)
115  {
116  $ilLog->write(__METHOD__.': Error reading EContent. '.$e->getMessage());
117  throw $e;
118  }
119  }
120 
121 
122 }
123 
124 
125 ?>