ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSCmsCourseCommandQueueHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once './Services/WebServices/ECS/interfaces/interface.ilECSCommandQueueHandler.php';
6 include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
7 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
8 
9 
16 {
17  private $server = null;
18  private $mid = 0;
19 
20 
24  public function __construct(ilECSSetting $server)
25  {
26  $this->server = $server;
27  }
28 
33  public function getServer()
34  {
35  return $this->server;
36  }
37 
42  public function getMid()
43  {
44  return $this->mid;
45  }
46 
52  public function checkAllocationActivation(ilECSSetting $server, $a_content_id)
53  {
54  try
55  {
56  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseConnector.php';
57  $crs_reader = new ilECSCourseConnector($server);
58  $details = $crs_reader->getCourse($a_content_id,true);
59  $this->mid = $details->getMySender();
60 
61  // Check if import is enabled
62  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
63  $part = ilECSParticipantSetting::getInstance($this->getServer()->getServerId(), $this->getMid());
64  if(!$part->isImportEnabled())
65  {
66  $GLOBALS['ilLog']->write(__METHOD__.': Import disabled for mid '.$this->getMid());
67  return false;
68  }
69  // Check course allocation setting
70  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php';
72  $this->getServer()->getServerId(),
73  $this->getMid()
74  );
75  $enabled = $gl_settings->isCourseAllocationEnabled();
76  if(!$enabled)
77  {
78  $GLOBALS['ilLog']->write(__METHOD__.': Course allocation disabled for '.$this->getMid());
79  }
80  return $enabled;
81  }
82  catch(ilECSConnectorException $e)
83  {
84  $GLOBALS['ilLog']->write(__METHOD__.': Reading course details failed with message '. $e->getMessage());
85  return false;
86  }
87  }
88 
89 
95  public function handleCreate(ilECSSetting $server, $a_content_id)
96  {
97  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
98  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
99  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseConnector.php';
100 
101  if(!$this->checkAllocationActivation($server, $a_content_id))
102  {
103  return true;
104  }
105  try
106  {
107  $course = $this->readCourse($server,$a_content_id);
108  $GLOBALS['ilLog']->write(__METHOD__.': '. print_r($course,true));
109  $this->doUpdate($a_content_id, $course);
110  return true;
111  }
112  catch(ilECSConnectorException $e)
113  {
114  $GLOBALS['ilLog']->write(__METHOD__.': Course creation failed with mesage ' . $e->getMessage());
115  return false;
116  }
117  return true;
118  }
119 
125  public function handleDelete(ilECSSetting $server, $a_content_id)
126  {
127  // nothing todo
128  return true;
129  }
130 
136  public function handleUpdate(ilECSSetting $server, $a_content_id)
137  {
138  if(!$this->checkAllocationActivation($server, $a_content_id))
139  {
140  return true;
141  }
142 
143  try
144  {
145  $course = $this->readCourse($server,$a_content_id);
146  $this->doUpdate($a_content_id, $course);
147  return true;
148  }
149  catch(ilECSConnectorException $e)
150  {
151  $GLOBALS['ilLog']->write(__METHOD__.': Course creation failed with mesage ' . $e->getMessage());
152  return false;
153  }
154  return true;
155  }
156 
157 
163  protected function doUpdate($a_content_id, $course)
164  {
165  $GLOBALS['ilLog']->write(__METHOD__.': Starting course creation/update');
166 
167  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseCreationHandler.php';
168  $creation_handler = new ilECSCourseCreationHandler($this->getServer(),$this->mid);
169  $creation_handler->handle($a_content_id, $course);
170  }
171 
172 
177  private function readCourse(ilECSSetting $server, $a_content_id, $a_details = false)
178  {
179  try
180  {
181  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseConnector.php';
182  $crs_reader = new ilECSCourseConnector($server);
183  return $crs_reader->getCourse($a_content_id,$a_details);
184  }
185  catch(ilECSConnectorException $e)
186  {
187  throw $e;
188  }
189 
190  }
191 }
192 ?>