ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjRemoteCourse.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 
35 {
36  const ACTIVATION_OFFLINE = 0;
38  const ACTIVATION_LIMITED = 2;
39 
40  protected $availability_type;
41  protected $end;
42  protected $start;
43  protected $local_information;
44  protected $remote_link;
45  protected $organization;
46  protected $mid;
47 
48  protected $auth_hash = '';
49 
56  public function __construct($a_id = 0,$a_call_by_reference = true)
57  {
58  global $ilDB;
59 
60  $this->type = "rcrs";
61  $this->ilObject($a_id,$a_call_by_reference);
62  $this->db = $ilDB;
63  }
64 
73  public static function _lookupOnline($a_obj_id)
74  {
75  global $ilDB;
76 
77  $query = "SELECT * FROM remote_course_settings ".
78  "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ";
79  $res = $ilDB->query($query);
80  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
81  switch($row->availability_type)
82  {
83  case self::ACTIVATION_UNLIMITED:
84  return true;
85 
86  case self::ACTIVATION_OFFLINE:
87  return false;
88 
89  case self::ACTIVATION_LIMITED:
90  return time() > $row->start && time < $row->end;
91 
92  default:
93  return false;
94  }
95 
96  return false;
97  }
98 
107  public static function _lookupOrganization($a_obj_id)
108  {
109  global $ilDB;
110 
111  $query = "SELECT organization FROM remote_course_settings ".
112  "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ";
113  $res = $ilDB->query($query);
114  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
115  {
116  return $row->organization;
117  }
118  return '';
119  }
120 
128  public function setOrganization($a_organization)
129  {
130  $this->organization = $a_organization;
131  }
132 
139  public function getOrganization()
140  {
141  return $this->organization;
142  }
143 
150  public function getLocalInformation()
151  {
153  }
154 
162  public function setLocalInformation($a_info)
163  {
164  $this->local_information = $a_info;
165  }
166 
174  public function setAvailabilityType($a_type)
175  {
176  $this->availability_type = $a_type;
177  }
178 
185  public function getAvailabilityType()
186  {
188  }
189 
197  public function setStartingTime($a_time)
198  {
199  $this->start = $a_time;
200  }
201 
209  public function getStartingTime()
210  {
211  return $this->start;
212  }
213 
221  public function setEndingTime($a_time)
222  {
223  $this->end = $a_time;
224  }
225 
233  public function getEndingTime()
234  {
235  return $this->end;
236  }
237 
245  public function setRemoteLink($a_link)
246  {
247  $this->remote_link = $a_link;
248  }
249 
257  public function getRemoteLink()
258  {
259  return $this->remote_link;
260  }
261 
269  public function getFullRemoteLink()
270  {
271  global $ilUser;
272 
273  include_once('./Services/WebServices/ECS/classes/class.ilECSUser.php');
274  $user = new ilECSUser($ilUser);
275  $ecs_user_data = $user->toGET();
276  return $this->getRemoteLink().'&ecs_hash='.$this->auth_hash.$ecs_user_data;
277  }
278 
285  public function getMID()
286  {
287  return $this->mid;
288  }
289 
297  public function setMID($a_mid)
298  {
299  $this->mid = $a_mid;
300  }
301 
309  public static function _lookupMID($a_obj_id)
310  {
311  global $ilDB;
312 
313  $query = "SELECT mid FROM remote_course_settings WHERE ".
314  "obj_id = ".$ilDB->quote($a_obj_id)." ";
315  $res = $ilDB->query($query);
316  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
317  {
318  return $row->mid;
319  }
320  return 0;
321  }
322 
331  public static function _lookupObjIdsByMID($a_mid)
332  {
333  global $ilDB;
334 
335  $query = "SELECT * FROM remote_course_settings ".
336  "WHERE mid = ".$ilDB->quote($a_mid)." ";
337 
338  $res = $ilDB->query($query);
339  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
340  {
341  $obj_ids[] = $row->obj_id;
342  }
343  return $obj_ids ? $obj_ids : array();
344  }
345 
352  public function createAuthResource()
353  {
354  global $ilLog;
355 
356  include_once('Services/WebServices/ECS/classes/class.ilECSAuth.php');
357  include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
358  include_once('Services/WebServices/ECS/classes/class.ilECSImport.php');
359 
360  try
361  {
362  $connector = new ilECSConnector();
363  $import = new ilECSImport($this->getId());
364  $auth = new ilECSAuth($import->getEContentId(),$import->getMID());
365  #$auth->setSOV(time());
366  #$auth->setEOV(time() + 7200);
367  $auth->setAbbreviation('K');
368  $connector->addAuth(@json_encode($auth));
369 
370  $this->auth_hash = $auth->getHash();
371  return true;
372  }
373  catch(ilECSConnectorException $exc)
374  {
375  $ilLog->write(__METHOD__.': Caught error from ECS Auth resource: '.$exc->getMessage());
376  return false;
377  }
378  }
379 
386  public function create($a_upload = false)
387  {
388  $obj_id = parent::create($a_upload);
389 
390  $query = "INSERT INTO remote_course_settings SET obj_id = ".$this->db->quote($this->getId())." ";
391  $res = $this->db->query($query);
392 
393  return $obj_id;
394  }
395 
396 
397 
405  public function update()
406  {
407  global $ilDB;
408 
409  if (!parent::update())
410  {
411  return false;
412  }
413 
414  $query = "UPDATE remote_course_settings SET ".
415  "availability_type = ".(int) $this->db->quote($this->getAvailabilityType()).", ".
416  "start = ".$this->db->quote($this->getStartingTime()).", ".
417  "end = ".$this->db->quote($this->getEndingTime()).", ".
418  "local_information = ".$this->db->quote($this->getLocalInformation()).", ".
419  "remote_link = ".$this->db->quote($this->getRemoteLink()).", ".
420  "mid = ".$this->db->quote($this->getMID()).", ".
421  "organization = ".$this->db->quote($this->getOrganization())." ".
422  "WHERE obj_id = ".$this->db->quote($this->getId())." ";
423 
424  $this->db->query($query);
425  return true;
426  }
427 
434  public function delete()
435  {
436  if(!parent::delete())
437  {
438  return false;
439  }
440 
441  //put here your module specific stuff
442  include_once('./Services/WebServices/ECS/classes/class.ilECSImport.php');
444 
445  $query = "DELETE FROM remote_course_settings WHERE obj_id = ".$this->db->quote($this->getId())." ";
446  $this->db->query($query);
447 
448 
449  return true;
450  }
451 
459  public function read($a_force_db = false)
460  {
461  parent::read($a_force_db);
462 
463  $query = "SELECT * FROM remote_course_settings ".
464  "WHERE obj_id = ".$this->db->quote($this->getId())." ";
465  $res = $this->db->query($query);
466  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
467  {
468  $this->setLocalInformation($row->local_information);
469  $this->setAvailabilityType($row->availability_type);
470  $this->setStartingTime($row->start);
471  $this->setEndingTime($row->end);
472  $this->setRemoteLink($row->remote_link);
473  $this->setMID($row->mid);
474  $this->setOrganization($row->organization);
475  }
476  }
477 
487  public static function _createFromECSEContent(ilECSEContent $ecs_content,$a_mid)
488  {
489  global $ilAppEventHandler;
490 
491  include_once('./Services/WebServices/ECS/classes/class.ilECSSettings.php');
492  $ecs_settings = ilECSSettings::_getInstance();
493 
494  $remote_crs = new ilObjRemoteCourse();
495  $remote_crs->setType('rcrs');
496  $remote_crs->setOwner(6);
497  $new_obj_id = $remote_crs->create();
498  $remote_crs->createReference();
499  $remote_crs->putInTree($ecs_settings->getImportId());
500  $remote_crs->setPermissions($ecs_settings->getImportId());
501 
502  $remote_crs->setECSImported($ecs_content->getEContentId(),$a_mid,$new_obj_id);
503  $remote_crs->updateFromECSContent($ecs_content);
504 
505  $ilAppEventHandler->raise('Modules/RemoteCourse','create',array('rcrs' => $remote_crs));
506  return $remote_crs;
507  }
508 
516  public function updateFromECSContent(ilECSEContent $ecs_content)
517  {
518  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
519  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
520  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
521 
523 
524  $this->setTitle($ecs_content->getTitle());
525  $this->setOrganization($ecs_content->getOrganization());
526  $this->setAvailabilityType($ecs_content->isOnline() ? self::ACTIVATION_UNLIMITED : self::ACTIVATION_OFFLINE);
527  $this->setRemoteLink($ecs_content->getURL());
528  $this->setMID($ecs_content->getOwner());
529 
530  $this->update();
531 
532 
533 
534  // Study courses
535  if($field = $mappings->getMappingByECSName('study_courses'))
536  {
537  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
538  $value->toggleDisabledStatus(true);
539  $value->setValue($ecs_content->getStudyCourses());
540  $value->save();
541  }
542 
543  // Lecturer
544  if($field = $mappings->getMappingByECSName('lecturer'))
545  {
546  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
547  $value->toggleDisabledStatus(true);
548  $value->setValue($ecs_content->getLecturers());
549  $value->save();
550  }
551  // CourseType
552  if($field = $mappings->getMappingByECSName('courseType'))
553  {
554  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
555  $value->toggleDisabledStatus(true);
556  $value->setValue($ecs_content->getCourseType());
557  $value->save();
558  }
559  // CourseID
560  if($field = $mappings->getMappingByECSName('courseID'))
561  {
562  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
563  $value->toggleDisabledStatus(true);
564  $value->setValue($ecs_content->getCourseID());
565  $value->save();
566  }
567  // Credits
568  if($field = $mappings->getMappingByECSName('credits'))
569  {
570  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
571  $value->toggleDisabledStatus(true);
572  $value->setValue($ecs_content->getCredits());
573  $value->save();
574  }
575 
576  if($field = $mappings->getMappingByECSName('semester_hours'))
577  {
578  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
579  $value->toggleDisabledStatus(true);
580  $value->setValue($ecs_content->getSemesterHours());
581  $value->save();
582  }
583  // Term
584  if($field = $mappings->getMappingByECSName('term'))
585  {
586  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
587  $value->toggleDisabledStatus(true);
588  $value->setValue($ecs_content->getTerm());
589  $value->save();
590  }
591 
592  // TIME PLACE OBJECT ########################
593  if($field = $mappings->getMappingByECSName('begin'))
594  {
595  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
596  $value->toggleDisabledStatus(true);
597 
599  {
602  $value->setValue($ecs_content->getTimePlace()->getUTBegin());
603  break;
604  default:
605  $value->setValue($ecs_content->getTimePlace()->getBegin());
606  break;
607  }
608  $value->save();
609  }
610  if($field = $mappings->getMappingByECSName('end'))
611  {
612  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
613  $value->toggleDisabledStatus(true);
615  {
618  $value->setValue($ecs_content->getTimePlace()->getUTEnd());
619  break;
620  default:
621  $value->setValue($ecs_content->getTimePlace()->getEnd());
622  break;
623  }
624  $value->save();
625  }
626  if($field = $mappings->getMappingByECSName('room'))
627  {
628  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
629  $value->toggleDisabledStatus(true);
630  $value->setValue($ecs_content->getTimePlace()->getRoom());
631  $value->save();
632  }
633  if($field = $mappings->getMappingByECSName('cycle'))
634  {
635  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
636  $value->toggleDisabledStatus(true);
637  $value->setValue($ecs_content->getTimePlace()->getCycle());
638  $value->save();
639  }
640  return true;
641  }
642 
649  public function setECSImported($a_econtent_id,$a_mid,$a_obj_id)
650  {
651  include_once('./Services/WebServices/ECS/classes/class.ilECSImport.php');
652  $import = new ilECSImport($a_obj_id);
653  $import->setEContentId($a_econtent_id);
654  $import->setMID($a_mid);
655  $import->save();
656  }
657 }
658 ?>