ILIAS  Release_4_2_x_branch Revision 61807
 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 ,'integer')." ";
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->r_start && time < $row->r_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 ,'integer')." ";
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 ,'integer')." ";
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 ,'integer')." ";
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  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
360 
361  try
362  {
363  $server_id = ilECSImport::lookupServerId($this->getId());
364 
365  $connector = new ilECSConnector(ilECSSetting::getInstanceByServerId($server_id));
366  $auth = new ilECSAuth();
367  $auth->setUrl($this->getRemoteLink());
368  $this->auth_hash = $connector->addAuth(@json_encode($auth),$this->getMID());
369  return true;
370  }
371  catch(ilECSConnectorException $exc)
372  {
373  $ilLog->write(__METHOD__.': Caught error from ECS Auth resource: '.$exc->getMessage());
374  return false;
375  }
376  }
377 
384  public function create($a_upload = false)
385  {
386  global $ilDB;
387 
388  $obj_id = parent::create($a_upload);
389 
390  $query = "INSERT INTO remote_course_settings (obj_id,local_information,availability_type,r_start,r_end,remote_link,mid,organization) ".
391  "VALUES( ".
392  $this->db->quote($this->getId() ,'integer').", ".
393  $ilDB->quote('','text').", ".
394  $ilDB->quote(0,'integer').", ".
395  $ilDB->quote(0,'integer').", ".
396  $ilDB->quote(0,'integer').", ".
397  $ilDB->quote('','text').", ".
398  $ilDB->quote(0,'integer').", ".
399  $ilDB->quote('','text')." ".
400  ")";
401  $res = $ilDB->manipulate($query);
402 
403  return $obj_id;
404  }
405 
406 
407 
415  public function update()
416  {
417  global $ilDB;
418 
419  if (!parent::update())
420  {
421  return false;
422  }
423 
424  $query = "UPDATE remote_course_settings SET ".
425  "availability_type = ".(int) $this->db->quote($this->getAvailabilityType() ,'integer').", ".
426  "r_start = ".$this->db->quote($this->getStartingTime() ,'integer').", ".
427  "r_end = ".$this->db->quote($this->getEndingTime() ,'integer').", ".
428  "local_information = ".$this->db->quote($this->getLocalInformation() ,'text').", ".
429  "remote_link = ".$this->db->quote($this->getRemoteLink() ,'text').", ".
430  "mid = ".$this->db->quote($this->getMID() ,'integer').", ".
431  "organization = ".$this->db->quote($this->getOrganization() ,'text')." ".
432  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
433  $res = $ilDB->manipulate($query);
434  return true;
435  }
436 
443  public function delete()
444  {
445  global $ilDB;
446 
447  if(!parent::delete())
448  {
449  return false;
450  }
451 
452  //put here your module specific stuff
453  include_once('./Services/WebServices/ECS/classes/class.ilECSImport.php');
455 
456  $query = "DELETE FROM remote_course_settings WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
457  $res = $ilDB->manipulate($query);
458 
459  return true;
460  }
461 
469  public function read($a_force_db = false)
470  {
471  parent::read($a_force_db);
472 
473  $query = "SELECT * FROM remote_course_settings ".
474  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
475  $res = $this->db->query($query);
476  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
477  {
478  $this->setLocalInformation($row->local_information);
479  $this->setAvailabilityType($row->availability_type);
480  $this->setStartingTime($row->r_start);
481  $this->setEndingTime($row->r_end);
482  $this->setRemoteLink($row->remote_link);
483  $this->setMID($row->mid);
484  $this->setOrganization($row->organization);
485  }
486  }
487 
497  public static function _createFromECSEContent($a_server_id,ilECSEContent $ecs_content, $a_mid)
498  {
499  global $ilAppEventHandler;
500 
501  include_once('./Services/WebServices/ECS/classes/class.ilECSSetting.php');
502  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
503  $ecs_settings = ilECSSetting::getInstanceByServerId($a_server_id);
504 
505  $remote_crs = new ilObjRemoteCourse();
506  $remote_crs->setType('rcrs');
507  $remote_crs->setOwner(0);
508  $new_obj_id = $remote_crs->create();
509  $remote_crs->createReference();
510  $remote_crs->putInTree(ilECSCategoryMapping::getMatchingCategory($a_server_id,$ecs_content));
511  $remote_crs->setPermissions($ecs_settings->getImportId());
512 
513  $remote_crs->setECSImported($a_server_id,$ecs_content->getEContentId(),$a_mid,$new_obj_id);
514  $remote_crs->updateFromECSContent($a_server_id,$ecs_content);
515 
516  $ilAppEventHandler->raise(
517  'Modules/RemoteCourse',
518  'create',
519  array(
520  'rcrs' => $remote_crs,
521  'server_id' => $a_server_id
522  )
523  );
524  return $remote_crs;
525  }
526 
534  public function updateFromECSContent($a_server_id,ilECSEContent $ecs_content)
535  {
536  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
537  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
538  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
539 
540  $mappings = ilECSDataMappingSettings::getInstanceByServerId($a_server_id);
541 
542  $this->setTitle($ecs_content->getTitle());
543  $this->setDescription($ecs_content->getAbstract());
544  $this->setOrganization($ecs_content->getOrganization());
545  $this->setAvailabilityType($ecs_content->isOnline() ? self::ACTIVATION_UNLIMITED : self::ACTIVATION_OFFLINE);
546  $this->setRemoteLink($ecs_content->getURL());
547  $this->setMID($ecs_content->getOwner());
548 
549  $this->update();
550 
551  // Study courses
552  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'study_courses'))
553  {
554  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
555  $value->toggleDisabledStatus(true);
556  $value->setValue($ecs_content->getStudyCourses());
557  $value->save();
558  }
559 
560  // Lecturer
561  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'lecturer'))
562  {
563  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
564  $value->toggleDisabledStatus(true);
565  $value->setValue($ecs_content->getLecturers());
566  $value->save();
567  }
568  // CourseType
569  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseType'))
570  {
571  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
572  $value->toggleDisabledStatus(true);
573  $value->setValue($ecs_content->getCourseType());
574  $value->save();
575  }
576  // CourseID
577  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'courseID'))
578  {
579  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
580  $value->toggleDisabledStatus(true);
581  $value->setValue($ecs_content->getCourseID());
582  $value->save();
583  }
584  // Credits
585  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'credits'))
586  {
587  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
588  $value->toggleDisabledStatus(true);
589  $value->setValue($ecs_content->getCredits());
590  $value->save();
591  }
592 
593  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'semester_hours'))
594  {
595  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
596  $value->toggleDisabledStatus(true);
597  $value->setValue($ecs_content->getSemesterHours());
598  $value->save();
599  }
600  // Term
601  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'term'))
602  {
603  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
604  $value->toggleDisabledStatus(true);
605  $value->setValue($ecs_content->getTerm());
606  $value->save();
607  }
608 
609  // TIME PLACE OBJECT ########################
610  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'begin'))
611  {
612  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
613  $value->toggleDisabledStatus(true);
614 
616  {
619  $value->setValue($ecs_content->getTimePlace()->getUTBegin());
620  break;
621  default:
622  $value->setValue($ecs_content->getTimePlace()->getBegin());
623  break;
624  }
625  $value->save();
626  }
627  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'end'))
628  {
629  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
630  $value->toggleDisabledStatus(true);
632  {
635  $value->setValue($ecs_content->getTimePlace()->getUTEnd());
636  break;
637  default:
638  $value->setValue($ecs_content->getTimePlace()->getEnd());
639  break;
640  }
641  $value->save();
642  }
643  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'room'))
644  {
645  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
646  $value->toggleDisabledStatus(true);
647  $value->setValue($ecs_content->getTimePlace()->getRoom());
648  $value->save();
649  }
650  if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS,'cycle'))
651  {
652  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
653  $value->toggleDisabledStatus(true);
654  $value->setValue($ecs_content->getTimePlace()->getCycle());
655  $value->save();
656  }
657 
658  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
659  ilECSCategoryMapping::handleUpdate($a_server_id,$ecs_content,$this->getId());
660 
661 
662  return true;
663  }
664 
671  public function setECSImported($a_server_id,$a_econtent_id,$a_mid,$a_obj_id)
672  {
673  include_once('./Services/WebServices/ECS/classes/class.ilECSImport.php');
674  $import = new ilECSImport($a_server_id,$a_obj_id);
675  $import->setEContentId($a_econtent_id);
676  $import->setMID($a_mid);
677  $import->save();
678  }
679 }
680 ?>