ILIAS  eassessment Revision 61809
 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 
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  global $ilDB;
389 
390  $obj_id = parent::create($a_upload);
391 
392  $query = "INSERT INTO remote_course_settings (obj_id,local_information,availability_type,r_start,r_end,remote_link,mid,organization) ".
393  "VALUES( ".
394  $this->db->quote($this->getId() ,'integer').", ".
395  $ilDB->quote('','text').", ".
396  $ilDB->quote(0,'integer').", ".
397  $ilDB->quote(0,'integer').", ".
398  $ilDB->quote(0,'integer').", ".
399  $ilDB->quote('','text').", ".
400  $ilDB->quote(0,'integer').", ".
401  $ilDB->quote('','text')." ".
402  ")";
403  $res = $ilDB->manipulate($query);
404 
405  return $obj_id;
406  }
407 
408 
409 
417  public function update()
418  {
419  global $ilDB;
420 
421  if (!parent::update())
422  {
423  return false;
424  }
425 
426  $query = "UPDATE remote_course_settings SET ".
427  "availability_type = ".(int) $this->db->quote($this->getAvailabilityType() ,'integer').", ".
428  "r_start = ".$this->db->quote($this->getStartingTime() ,'integer').", ".
429  "r_end = ".$this->db->quote($this->getEndingTime() ,'integer').", ".
430  "local_information = ".$this->db->quote($this->getLocalInformation() ,'text').", ".
431  "remote_link = ".$this->db->quote($this->getRemoteLink() ,'text').", ".
432  "mid = ".$this->db->quote($this->getMID() ,'integer').", ".
433  "organization = ".$this->db->quote($this->getOrganization() ,'text')." ".
434  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
435  $res = $ilDB->manipulate($query);
436  return true;
437  }
438 
445  public function delete()
446  {
447  global $ilDB;
448 
449  if(!parent::delete())
450  {
451  return false;
452  }
453 
454  //put here your module specific stuff
455  include_once('./Services/WebServices/ECS/classes/class.ilECSImport.php');
457 
458  $query = "DELETE FROM remote_course_settings WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
459  $res = $ilDB->manipulate($query);
460 
461  return true;
462  }
463 
471  public function read($a_force_db = false)
472  {
473  parent::read($a_force_db);
474 
475  $query = "SELECT * FROM remote_course_settings ".
476  "WHERE obj_id = ".$this->db->quote($this->getId() ,'integer')." ";
477  $res = $this->db->query($query);
478  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
479  {
480  $this->setLocalInformation($row->local_information);
481  $this->setAvailabilityType($row->availability_type);
482  $this->setStartingTime($row->r_start);
483  $this->setEndingTime($row->r_end);
484  $this->setRemoteLink($row->remote_link);
485  $this->setMID($row->mid);
486  $this->setOrganization($row->organization);
487  }
488  }
489 
499  public static function _createFromECSEContent(ilECSEContent $ecs_content,$a_mid)
500  {
501  global $ilAppEventHandler;
502 
503  include_once('./Services/WebServices/ECS/classes/class.ilECSSettings.php');
504  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
505  $ecs_settings = ilECSSettings::_getInstance();
506 
507  $remote_crs = new ilObjRemoteCourse();
508  $remote_crs->setType('rcrs');
509  $remote_crs->setOwner(6);
510  $new_obj_id = $remote_crs->create();
511  $remote_crs->createReference();
512  $remote_crs->putInTree(ilECSCategoryMapping::getMatchingCategory($ecs_content));
513  $remote_crs->setPermissions($ecs_settings->getImportId());
514 
515  $remote_crs->setECSImported($ecs_content->getEContentId(),$a_mid,$new_obj_id);
516  $remote_crs->updateFromECSContent($ecs_content);
517 
518  $ilAppEventHandler->raise('Modules/RemoteCourse','create',array('rcrs' => $remote_crs));
519  return $remote_crs;
520  }
521 
529  public function updateFromECSContent(ilECSEContent $ecs_content)
530  {
531  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
532  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
533  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
534 
536 
537  $this->setTitle($ecs_content->getTitle());
538  $this->setOrganization($ecs_content->getOrganization());
539  $this->setAvailabilityType($ecs_content->isOnline() ? self::ACTIVATION_UNLIMITED : self::ACTIVATION_OFFLINE);
540  $this->setRemoteLink($ecs_content->getURL());
541  $this->setMID($ecs_content->getOwner());
542 
543  $this->update();
544 
545 
546 
547  // Study courses
548  if($field = $mappings->getMappingByECSName('study_courses'))
549  {
550  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
551  $value->toggleDisabledStatus(true);
552  $value->setValue($ecs_content->getStudyCourses());
553  $value->save();
554  }
555 
556  // Lecturer
557  if($field = $mappings->getMappingByECSName('lecturer'))
558  {
559  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
560  $value->toggleDisabledStatus(true);
561  $value->setValue($ecs_content->getLecturers());
562  $value->save();
563  }
564  // CourseType
565  if($field = $mappings->getMappingByECSName('courseType'))
566  {
567  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
568  $value->toggleDisabledStatus(true);
569  $value->setValue($ecs_content->getCourseType());
570  $value->save();
571  }
572  // CourseID
573  if($field = $mappings->getMappingByECSName('courseID'))
574  {
575  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
576  $value->toggleDisabledStatus(true);
577  $value->setValue($ecs_content->getCourseID());
578  $value->save();
579  }
580  // Credits
581  if($field = $mappings->getMappingByECSName('credits'))
582  {
583  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
584  $value->toggleDisabledStatus(true);
585  $value->setValue($ecs_content->getCredits());
586  $value->save();
587  }
588 
589  if($field = $mappings->getMappingByECSName('semester_hours'))
590  {
591  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
592  $value->toggleDisabledStatus(true);
593  $value->setValue($ecs_content->getSemesterHours());
594  $value->save();
595  }
596  // Term
597  if($field = $mappings->getMappingByECSName('term'))
598  {
599  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
600  $value->toggleDisabledStatus(true);
601  $value->setValue($ecs_content->getTerm());
602  $value->save();
603  }
604 
605  // TIME PLACE OBJECT ########################
606  if($field = $mappings->getMappingByECSName('begin'))
607  {
608  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
609  $value->toggleDisabledStatus(true);
610 
612  {
615  $value->setValue($ecs_content->getTimePlace()->getUTBegin());
616  break;
617  default:
618  $value->setValue($ecs_content->getTimePlace()->getBegin());
619  break;
620  }
621  $value->save();
622  }
623  if($field = $mappings->getMappingByECSName('end'))
624  {
625  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
626  $value->toggleDisabledStatus(true);
628  {
631  $value->setValue($ecs_content->getTimePlace()->getUTEnd());
632  break;
633  default:
634  $value->setValue($ecs_content->getTimePlace()->getEnd());
635  break;
636  }
637  $value->save();
638  }
639  if($field = $mappings->getMappingByECSName('room'))
640  {
641  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
642  $value->toggleDisabledStatus(true);
643  $value->setValue($ecs_content->getTimePlace()->getRoom());
644  $value->save();
645  }
646  if($field = $mappings->getMappingByECSName('cycle'))
647  {
648  $value = ilAdvancedMDValue::_getInstance($this->getId(),$field);
649  $value->toggleDisabledStatus(true);
650  $value->setValue($ecs_content->getTimePlace()->getCycle());
651  $value->save();
652  }
653 
654  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMapping.php';
655  ilECSCategoryMapping::handleUpdate($ecs_content,$this->getId());
656 
657 
658  return true;
659  }
660 
667  public function setECSImported($a_econtent_id,$a_mid,$a_obj_id)
668  {
669  include_once('./Services/WebServices/ECS/classes/class.ilECSImport.php');
670  $import = new ilECSImport($a_obj_id);
671  $import->setEContentId($a_econtent_id);
672  $import->setMID($a_mid);
673  $import->save();
674  }
675 }
676 ?>