• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/Course/classes/class.ilCourseObjectiveMaterials.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00033 class ilCourseObjectiveMaterials
00034 {
00035         var $db = null;
00036 
00037         var $objective_id = null;
00038         var $lms;
00039 
00040         public function __construct($a_objective_id)
00041         {
00042                 global $ilDB;
00043 
00044                 $this->db =& $ilDB;
00045         
00046                 $this->objective_id = $a_objective_id;
00047 
00048                 $this->__read();
00049         }
00050         
00060         public function cloneDependencies($a_new_objective,$a_copy_id)
00061         {
00062                 global $ilObjDataCache,$ilLog;
00063                 
00064                 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
00065                 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
00066                 $mappings = $cwo->getMappings();
00067                 #$ilLog->write(__METHOD__.': 1');
00068                 foreach($this->getMaterials() as $material)
00069                 {
00070                 #$ilLog->write(__METHOD__.': 2');
00071                         // Copy action omit ?
00072                         if(!isset($mappings["$material[ref_id]"]) or !$mappings["$material[ref_id]"])
00073                         {
00074                                 continue;
00075                         }
00076                 #$ilLog->write(__METHOD__.': 3');
00077                         $material_ref_id = $material['ref_id'];
00078                         $material_rbac_obj_id = $ilObjDataCache->lookupObjId($material_ref_id);
00079                         $material_obj_id = $material['obj_id'];
00080                         $new_ref_id = $mappings[$material_ref_id];
00081                         $new_rbac_obj_id = $ilObjDataCache->lookupObjId($new_ref_id);
00082                 #$ilLog->write(__METHOD__.': 4');
00083                         
00084                         // Link
00085                         if($new_rbac_obj_id == $material_rbac_obj_id)
00086                         {
00087                 #$ilLog->write(__METHOD__.': 5');
00088                                 $ilLog->write(__METHOD__.': Material has been linked. Keeping object id.');
00089                                 $new_obj_id = $material_obj_id;
00090                         }
00091                         elseif($material['type'] == 'st')
00092                         {
00093                 #$ilLog->write(__METHOD__.': 6');
00094                                 // Chapter assignment
00095                                 $new_material_info = isset($mappings[$material_ref_id.'_'.$material_obj_id]) ?
00096                                         $mappings[$material_ref_id.'_'.$material_obj_id] :
00097                                         array();
00098                                 $new_material_arr = explode('_',$new_material_info);
00099                                 if(!isset($new_material_arr[1]) or !$new_material_arr[1])
00100                                 {
00101                                         $ilLog->write(__METHOD__.': No mapping found for chapter: '.$material_obj_id);
00102                                         continue;
00103                                 }
00104                                 $new_obj_id = $new_material_arr[1];
00105                                 $ilLog->write(__METHOD__.': New material id is: '.$new_obj_id);
00106                         }
00107                         else
00108                         {
00109                 #$ilLog->write(__METHOD__.': 7');
00110                                 // Any type
00111                                 $new_obj_id = $ilObjDataCache->lookupObjId($mappings[$material_ref_id]);
00112                         }
00113         
00114                 #$ilLog->write(__METHOD__.': 8');
00115                         $new_material = new ilCourseObjectiveMaterials($a_new_objective);
00116                 #$ilLog->write(__METHOD__.': 8.1');
00117                         $new_material->setLMRefId($new_ref_id);
00118                 #$ilLog->write(__METHOD__.': 8.2');
00119                         $new_material->setLMObjId($new_obj_id);
00120                 #$ilLog->write(__METHOD__.': 8.3');
00121                         $new_material->setType($material['type']);
00122                 #$ilLog->write(__METHOD__.': 8.4');
00123                         $new_material->add();
00124                 #$ilLog->write(__METHOD__.': 9');
00125                         
00126                 }
00127         }
00128         
00129         
00130 
00141         public static function _getAssignableMaterials($a_container_id)
00142         {
00143                 global $tree,$ilDB;
00144                 
00145                 $all_materials = $tree->getSubTree($tree->getNodeData($a_container_id),true);
00146                 $all_materials = ilUtil::sortArray($all_materials,'title','asc');
00147                 
00148                 // Filter
00149                 foreach($all_materials as $material)
00150                 {
00151                         switch($material['type'])
00152                         {
00153                                 case 'tst':
00154                                 case 'fold':
00155                                 case 'grp':
00156                                 case 'rolf':
00157                                 case 'crs':
00158                                         continue;
00159                                 
00160                                 default:
00161                                         $assignable[] = $material;
00162                                         break;
00163                         }
00164                 }
00165                 return $assignable ? $assignable : array();
00166         }
00167         
00176         public static function _getAllAssignedMaterials($a_container_id)
00177         {
00178                 global $ilDB;
00179                 
00180                 $query = "SELECT DISTINCT(com.ref_id) as ref_id FROM crs_objectives as co ".
00181                         "JOIN crs_objective_lm as com ON co.objective_id = com.objective_id ".
00182                         "JOIN object_reference as obr ON com.ref_id = obr.ref_id ".
00183                         "JOIN object_data as obd ON obr.obj_id = obd.obj_id ".
00184                         "WHERE co.crs_id = ".$ilDB->quote($a_container_id)." ".
00185                         "ORDER BY obd.title ";
00186                         
00187                 $res = $ilDB->query($query);
00188                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00189                 {
00190                         $ref_ids[] = $row->ref_id;
00191                 }
00192                 return $ref_ids ? $ref_ids : array();
00193         }
00194 
00195         public function getMaterials()
00196         {
00197                 return $this->lms ? $this->lms : array();
00198         }
00199 
00200         function getChapters()
00201         {
00202                 foreach($this->lms as $lm_data)
00203                 {
00204                         if($lm_data['type'] == 'st')
00205                         {
00206                                 $chapters[] = $lm_data;
00207                         }
00208                 }
00209                 return $chapters ? $chapters : array();
00210         }
00211         
00212         function getLM($lm_id)
00213         {
00214                 return $this->lms[$lm_id] ? $this->lms[$lm_id] : array();
00215         }
00216 
00217         function getObjectiveId()
00218         {
00219                 return $this->objective_id;
00220         }
00221 
00222         function setLMRefId($a_ref_id)
00223         {
00224                 $this->lm_ref_id = $a_ref_id;
00225         }
00226         function getLMRefId()
00227         {
00228                 return $this->lm_ref_id ? $this->lm_ref_id : 0;
00229         }
00230         function setLMObjId($a_obj_id)
00231         {
00232                 $this->lm_obj_id = $a_obj_id;
00233         }
00234         function getLMObjId()
00235         {
00236                 return $this->lm_obj_id ? $this->lm_obj_id : 0;
00237         }
00238         function setType($a_type)
00239         {
00240                 $this->type = $a_type;
00241         }
00242         function getType()
00243         {
00244                 return $this->type;
00245         }
00246         
00255         public function isAssigned($a_ref_id)
00256         {
00257                 $query = "SELECT * FROM crs_objective_lm ".
00258                         "WHERE ref_id = ".$this->db->quote($a_ref_id)." ".
00259                         "AND objective_id = ".$this->db->quote($this->getObjectiveId())." ".
00260                         "AND type != 'st'";
00261                 $res = $this->db->query($query);
00262                 return $res->numRows() ? true : false;
00263         }
00264 
00273         public function isChapterAssigned($a_ref_id,$a_obj_id)
00274         {
00275                 $query = "SELECT * FROM crs_objective_lm ".
00276                         "WHERE ref_id = ".$this->db->quote($a_ref_id)." ".
00277                         "AND obj_id = ".$this->db->quote($a_obj_id)." ".
00278                         "AND objective_id = ".$this->db->quote($this->getObjectiveId())." ".
00279                         "AND type = 'st'";
00280                 $res = $this->db->query($query);
00281                 return $res->numRows() ? true : false;
00282         }
00283         function checkExists()
00284         {
00285                 global $ilDB;
00286                 
00287                 if($this->getLMObjId())
00288                 {
00289                         $query = "SELECT * FROM crs_objective_lm ".
00290                                 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00291                                 "AND ref_id = ".$ilDB->quote($this->getLMRefId())." ".
00292                                 "AND obj_id = ".$ilDB->quote($this->getLMObjId())." ";
00293                 }
00294                 else
00295                 {
00296                         $query = "SELECT * FROM crs_objective_lm ".
00297                                 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00298                                 "AND ref_id = ".$ilDB->quote($this->getLMRefId())." ";
00299                 }
00300 
00301                 $res = $this->db->query($query);
00302 
00303                 return $res->numRows() ? true : false;
00304         }
00305 
00306         function add()
00307         {
00308                 global $ilDB;
00309                 
00310                 $query = "INSERT INTO crs_objective_lm ".
00311                         "SET objective_id = ".$ilDB->quote($this->getObjectiveId()).", ".
00312                         "ref_id = ".$ilDB->quote($this->getLMRefId()).", ".
00313                         "obj_id = ".$ilDB->quote($this->getLMObjId()).", ".
00314                         "type = ".$ilDB->quote($this->getType())."";
00315 
00316                 $this->db->query($query);
00317 
00318                 return true;
00319         }
00320         function delete($lm_id)
00321         {
00322                 global $ilDB;
00323                 
00324                 if(!$lm_id)
00325                 {
00326                         return false;
00327                 }
00328 
00329                 $query = "DELETE FROM crs_objective_lm ".
00330                         "WHERE lm_ass_id = ".$ilDB->quote($lm_id)." ";
00331 
00332                 $this->db->query($query);
00333 
00334                 return true;
00335         }
00336 
00337         function deleteAll()
00338         {
00339                 global $ilDB;
00340                 
00341                 $query = "DELETE FROM crs_objective_lm ".
00342                         "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ";
00343 
00344                 $this->db->query($query);
00345 
00346                 return true;
00347         }
00348 
00349         // PRIVATE
00350         function __read()
00351         {
00352                 global $tree,$ilDB;
00353                 
00354                 include_once('Modules/Course/classes/class.ilCourseObjective.php');
00355                 $container_ref_ids = ilObject::_getAllReferences(ilCourseObjective::_lookupContainerIdByObjectiveId($this->objective_id));
00356                 $container_ref_id  = current($container_ref_ids);
00357 
00358                 $this->lms = array();
00359                 $query = "SELECT lm_ass_id,lm.ref_id,lm.obj_id,lm.type FROM crs_objective_lm as lm ".
00360                         "JOIN object_reference as obr ON lm.ref_id = obr.ref_id ".
00361                         "JOIN object_data as obd ON obr.obj_id = obd.obj_id ".
00362                         "LEFT JOIN lm_data as lmd ON lmd.obj_id = lm.obj_id ".
00363                         "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00364                         "ORDER BY obd.title,lmd.title";
00365                         
00366                 $res = $this->db->query($query);
00367                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00368                 {
00369                         if(!$tree->isInTree($row->ref_id) or !$tree->isGrandChild($container_ref_id,$row->ref_id))
00370                         {
00371                                 $this->delete($row->lm_ass_id);
00372                                 continue;
00373                         }
00374                         $lm['ref_id'] = $row->ref_id;
00375                         $lm['obj_id'] = $row->obj_id;
00376                         $lm['type'] = $row->type;
00377                         $lm['lm_ass_id'] = $row->lm_ass_id;
00378 
00379                         $this->lms[$row->lm_ass_id] = $lm;
00380                 }
00381                 return true;
00382         }
00383         
00384 }
00385 ?>

Generated on Fri Dec 13 2013 17:56:49 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1