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

Modules/Course/classes/Event/class.ilEventItems.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 
00034 class ilEventItems
00035 {
00036         var $ilErr;
00037         var $ilDB;
00038         var $tree;
00039         var $lng;
00040 
00041         var $event_id = null;
00042         var $items = array();
00043 
00044 
00045         function ilEventItems($a_event_id)
00046         {
00047                 global $ilErr,$ilDB,$lng,$tree;
00048 
00049                 $this->ilErr =& $ilErr;
00050                 $this->db  =& $ilDB;
00051                 $this->lng =& $lng;
00052 
00053                 $this->event_id = $a_event_id;
00054                 $this->__read();
00055         }
00056 
00057         function getEventId()
00058         {
00059                 return $this->event_id;
00060         }
00061         function setEventId($a_event_id)
00062         {
00063                 $this->event_id = $a_event_id;
00064         }
00065         function getItems()
00066         {
00067                 return $this->items ? $this->items : array();
00068         }
00069         function setItems($a_items)
00070         {
00071                 $this->items = array();
00072                 foreach($a_items as $item_id)
00073                 {
00074                         $this->items[] = (int) $item_id;
00075                 }
00076         }
00077         function delete()
00078         {
00079                 return ilEventItems::_delete($this->getEventId());
00080         }
00081         
00082         function _delete($a_event_id)
00083         {
00084                 global $ilDB;
00085 
00086                 $query = "DELETE FROM event_items ".
00087                         "WHERE event_id = ".$ilDB->quote($a_event_id)." ";
00088                 $ilDB->query($query);
00089                 return true;
00090         }
00091         
00092         function update()
00093         {
00094                 global $ilDB;
00095                 
00096                 $this->delete();
00097                 
00098                 foreach($this->items as $item)
00099                 {
00100                         $query = "INSERT INTO event_items ".
00101                                 "SET event_id = ".$ilDB->quote($this->getEventId()).", ".
00102                                 "item_id = ".$ilDB->quote($item)." ";
00103                         $this->db->query($query);
00104                 }
00105                 return true;
00106         }
00107         
00108         function _getItemsOfContainer($a_obj_id)
00109         {
00110                 global $ilDB;
00111 
00112                 $query = "SELECT * FROM event AS e ".
00113                         "JOIN event_items AS ei ON e.event_id = ei.event_id ".
00114                         "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ";
00115 
00116                 $res = $ilDB->query($query);
00117                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00118                 {
00119                         $items[] = $row->item_id;
00120                 }
00121                 return $items ? $items : array();
00122         }
00123         
00132         public static function _getItemsOfEvent($a_event_id)
00133         {
00134                 global $ilDB;
00135                 
00136                 $query = "SELECT * FROM event_items ".
00137                         "WHERE event_id = ".$ilDB->quote($a_event_id);
00138                 $res = $ilDB->query($query);
00139                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00140                 {
00141                         $items[] = $row->item_id;
00142                 }
00143                 return $items ? $items : array();
00144         }
00145 
00146         function _isAssigned($a_item_id)
00147         {
00148                 global $ilDB;
00149 
00150                 $query = "SELECT * FROM event_items ".
00151                         "WHERE item_id = ".$ilDB->quote($a_item_id)." ";
00152                 $res = $ilDB->query($query);
00153 
00154                 return $res->numRows() ? true : false;
00155         }
00156         
00165         public function cloneItems($a_source_event,$a_copy_id)
00166         {
00167                 global $ilObjDataCache,$ilLog;
00168                 
00169                 $ilLog->write(__METHOD__.': Begin course event items ...');
00170                 
00171                 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
00172                 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
00173                 $mappings = $cwo->getMappings();
00174                 
00175                 $new_items = array(); 
00176                 foreach(ilEventItems::_getItemsOfEvent($a_source_event) as $item_id)
00177                 {
00178                         if(isset($mappings[$item_id]) and $mappings[$item_id])
00179                         {
00180                                 $ilLog->write(__METHOD__.': Clone event item nr. '.$item_id);
00181                                 $new_items[] = $mappings[$item_id];
00182                         }
00183                         else
00184                         {
00185                                 $ilLog->write(__METHOD__.': No mapping found for event item nr. '.$item_id);
00186                         }
00187                 }
00188                 $this->setItems($new_items);
00189                 $this->update();
00190                 $ilLog->write(__METHOD__.': Finished cloning course event items ...');
00191                 return true;
00192 
00193         }
00194 
00195 
00196         // PRIVATE
00197         function __read()
00198         {
00199                 global $ilDB,$tree;
00200                 
00201                 $query = "SELECT * FROM event_items ".
00202                         "WHERE event_id = ".$ilDB->quote($this->getEventId())." ";
00203 
00204                 $res = $this->db->query($query);
00205                 $this->items = array();
00206                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00207                 {
00208                         if($tree->isDeleted($row->item_id))
00209                         {
00210                                 continue;
00211                         }
00212                         if(!$tree->isInTree($row->item_id))
00213                         {
00214                                 $query = "DELETE FROM event_items ".
00215                                         "WHERE item_id = ".$ilDB->quote($row->item_id);
00216                                 $ilDB->query($query);
00217                                 continue;
00218                         }
00219                         
00220                         $this->items[] = (int) $row->item_id;
00221                 }
00222                 return true;
00223         }
00224                 
00225 }
00226 ?>

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