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

Services/Tracking/classes/class.ilLPCollections.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 
00035 class ilLPCollections
00036 {
00037         var $db = null;
00038 
00039         var $obj_id = null;
00040         var $items = array();
00041 
00042         function ilLPCollections($a_obj_id)
00043         {
00044                 global $ilObjDataCache,$ilDB;
00045 
00046                 $this->db =& $ilDB;
00047 
00048                 $this->obj_id = $a_obj_id;
00049 
00050                 $this->__read();
00051         }
00052 
00053         function getObjId()
00054         {
00055                 return (int) $this->obj_id;
00056         }
00057 
00058         function getItems()
00059         {
00060                 return $this->items;
00061         }
00062 
00063         function isAssigned($a_obj_id)
00064         {
00065                 return (bool) in_array($a_obj_id,$this->items);
00066         }
00067 
00068         function add($item_id)
00069         {
00070                 if($this->isAssigned($item_id))
00071                 {
00072                         return false;
00073                 }
00074 
00075                 $query = "INSERT INTO ut_lp_collections ".
00076                         "SET obj_id = '".$this->obj_id."', ".
00077                         "item_id = '".(int) $item_id."'";
00078                 $this->db->query($query);
00079                 
00080                 $this->__read();
00081 
00082                 return true;
00083         }
00084 
00085         function delete($item_id)
00086         {
00087                 $query = "DELETE FROM ut_lp_collections ".
00088                         "WHERE item_id = '".$item_id."' ".
00089                         "AND obj_id = '".$this->obj_id."'";
00090                 $this->db->query($query);
00091 
00092                 $this->__read();
00093 
00094                 return true;
00095         }
00096 
00097 
00098         // Static
00099         function _getPossibleItems($a_target_id)
00100         {
00101                 global $tree;
00102 
00103                 $node_data = $tree->getNodeData($a_target_id);
00104                 foreach($tree->getSubTree($node_data) as $node)
00105                 {
00106                         switch($node['type'])
00107                         {
00108                                 case 'sahs':
00109                                 case 'lm':
00110                                 case 'tst':
00111                                         $all_possible["$node[ref_id]"] = $node['obj_id'];
00112                                         break;
00113                         }
00114                 }
00115 
00116                 return $all_possible ? $all_possible : array();
00117         }
00118 
00119         function _getCountPossibleItems($a_target_id)
00120         {
00121                 return count(ilLPCollections::_getPossibleItems($a_target_id));
00122         }
00123 
00124         function _getCountPossibleSAHSItems($a_target_id)
00125         {
00126                 return count(ilLPCollections::_getPossibleSAHSItems($a_target_id));
00127         }
00128 
00129 
00134         function _getPossibleSAHSItems($target_id)
00135         {
00136                 include_once './content/classes/class.ilObjSAHSLearningModule.php';
00137 
00138                 switch(ilObjSAHSLearningModule::_lookupSubType($target_id))
00139                 {
00140                         case 'hacp':
00141                         case 'aicc':
00142                                 include_once './content/classes/class.ilObjAICCLearningModule.php';
00143 
00144                                 foreach(ilObjAICCLearningModule::_getTrackingItems($target_id) as $item)
00145                                 {
00146                                         $items["$item[obj_id]"]['title'] = $item['title'];
00147                                         #$items[$item->getId()]['title'] = $item->getTitle();
00148                                 }
00149                                 return $items ? $items : array();
00150 
00151                         case 'scorm':
00152                                 include_once './content/classes/class.ilObjSCORMLearningModule.php';
00153                                 include_once './content/classes/SCORM/class.ilSCORMItem.php';
00154 
00155                                 foreach(ilObjSCORMLearningModule::_getTrackingItems($target_id) as $item)
00156                                 {
00157                                         $items[$item->getId()]['title'] = $item->getTitle();
00158                                 }
00159                                 return $items ? $items : array();
00160                 }
00161                 return array();
00162         }
00163 
00164 
00165         function _deleteAll($a_obj_id)
00166         {
00167                 global $ilDB;
00168 
00169                 $query = "DELETE FROM ut_lp_collections ".
00170                         "WHERE obj_id = '".$a_obj_id."'";
00171                 $ilDB->query($query);
00172 
00173                 return true;
00174         }
00175 
00176         function _getItems($a_obj_id)
00177         {
00178                 global $ilObjDataCache;
00179                 global $ilDB;
00180 
00181                 if($ilObjDataCache->lookupType($a_obj_id) == 'crs')
00182                 {
00183                         $course_ref_ids = ilObject::_getAllReferences($a_obj_id);
00184                         $course_ref_id = end($course_ref_ids);
00185                 }
00186 
00187                 $query = "SELECT * FROM ut_lp_collections WHERE obj_id = '".(int) $a_obj_id."'";
00188                 $res = $ilDB->query($query);
00189                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00190                 {
00191                         if($ilObjDataCache->lookupType($a_obj_id) == 'crs')
00192                         {
00193                                 if(!in_array($row->item_id,ilLPCollections::_getPossibleItems($course_ref_id)))
00194                                 {
00195                                         $query = "DELETE FROM ut_lp_collections ".
00196                                                 "WHERE obj_id = '".$a_obj_id."' ".
00197                                                 "AND item_id = '".$row->item_id."'";
00198                                         $ilDB->query($query);
00199                                         continue;
00200                                 }
00201                         }
00202                         $items[] = $row->item_id;
00203                 }
00204                 return $items ? $items : array();
00205         }
00206 
00207         // Private
00208         function __read()
00209         {
00210                 global $ilObjDataCache;
00211 
00212                 if($ilObjDataCache->lookupType($this->getObjId()) == 'crs')
00213                 {
00214                         $course_ref_ids = ilObject::_getAllReferences($this->getObjId());
00215                         $course_ref_id = end($course_ref_ids);
00216                 }
00217 
00218                 $query = "SELECT * FROM ut_lp_collections WHERE obj_id = '".$this->db->quote($this->obj_id)."'";
00219                 $res = $this->db->query($query);
00220                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00221                 {
00222                         if($ilObjDataCache->lookupType($this->getObjId()) == 'crs')
00223                         {
00224                                 if(!in_array($row->item_id,ilLPCollections::_getPossibleItems($course_ref_id)))
00225                                 {
00226                                         $query = "DELETE FROM ut_lp_collections ".
00227                                                 "WHERE obj_id = '".$this->getObjId()."' ".
00228                                                 "AND item_id = '".$row->item_id."'";
00229                                         $this->db->query($query);
00230                                         continue;
00231                                 }
00232                         }
00233                         $this->items[] = $row->item_id;
00234                 }
00235                 
00236         }
00237 }
00238 ?>

Generated on Fri Dec 13 2013 11:57:59 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1