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

Modules/Course/classes/class.ilCourseStart.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2005 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 
00033 class ilCourseStart
00034 {
00035         var $db;
00036 
00037         var $ref_id;
00038         var $id;
00039         var $start_objs = array();
00040 
00047         function ilCourseStart($a_course_ref_id,$a_course_obj_id)
00048         {
00049                 global $ilDB;
00050 
00051                 $this->db =& $ilDB;
00052 
00053                 $this->ref_id = $a_course_ref_id;
00054                 $this->id = $a_course_obj_id;
00055 
00056                 $this->__read();
00057         }
00058         function setId($a_id)
00059         {
00060                 $this->id = $a_id;
00061         }
00062         function getId()
00063         {
00064                 return $this->id;
00065         }
00066         function setRefId($a_ref_id)
00067         {
00068                 $this->ref_id = $a_ref_id;
00069         }
00070         function getRefId()
00071         {
00072                 return $this->ref_id;
00073         }
00074         function getStartObjects()
00075         {
00076                 return $this->start_objs ? $this->start_objs : array();
00077         }
00078         
00087         public function cloneDependencies($a_target_id,$a_copy_id)
00088         {
00089                 global $ilObjDataCache,$ilLog;
00090                 
00091                 $ilLog->write(__METHOD__.': Begin course start objects...');
00092                 
00093                 $new_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
00094                 $start = new ilCourseStart($a_target_id,$new_obj_id);
00095                 
00096                 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
00097                 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
00098                 $mappings = $cwo->getMappings();
00099                 foreach($this->getStartObjects() as $start_id => $data)
00100                 {
00101                         $item_ref_id = $data['item_ref_id'];
00102                         if(isset($mappings[$item_ref_id]) and $mappings[$item_ref_id])
00103                         {
00104                                 $ilLog->write(__METHOD__.': Clone start object nr. '.$item_ref_id);
00105                                 $start->add($mappings[$item_ref_id]);
00106                         }
00107                         else
00108                         {
00109                                 $ilLog->write(__METHOD__.': No mapping found for start object nr. '.$item_ref_id);
00110                         }
00111                 }
00112                 $ilLog->write(__METHOD__.': ... end course start objects');
00113                 return true;
00114         }
00115 
00116         function delete($a_crs_start_id)
00117         {
00118                 global $ilDB;
00119                 
00120                 $query = "DELETE FROM crs_start ".
00121                         "WHERE crs_start_id = ".$ilDB->quote($a_crs_start_id)." ".
00122                         "AND crs_id = ".$ilDB->quote($this->getId())." ";
00123 
00124                 $this->db->query($query);
00125 
00126                 return true;
00127         }
00128 
00129         function exists($a_item_ref_id)
00130         {
00131                 global $ilDB;
00132                 
00133                 $query = "SELECT * FROM crs_start ".
00134                         "WHERE crs_id = ".$ilDB->quote($this->getId())." ".
00135                         "AND item_ref_id = ".$a_item_ref_id." ";
00136 
00137                 $res = $this->db->query($query);
00138 
00139                 return $res->numRows() ? true : false;
00140         }
00141 
00142         function add($a_item_ref_id)
00143         {
00144                 global $ilDB;
00145                 
00146                 if($a_item_ref_id)
00147                 {
00148                         $query = "INSERT INTO crs_start ".
00149                                 "SET crs_id = ".$ilDB->quote($this->getId()).", ".
00150                                 "item_ref_id = ".$ilDB->quote($a_item_ref_id)." ";
00151 
00152                         $this->db->query($query);
00153 
00154                         return true;
00155                 }
00156                 return false;
00157         }
00158 
00159         function __deleteAll()
00160         {
00161                 global $ilDB;
00162                 
00163                 $query = "DELETE FROM crs_start ".
00164                         "WHERE crs_id = ".$ilDB->quote($this->getId())." ";
00165 
00166 
00167                 $this->db->query($query);
00168 
00169                 return true;
00170         }
00171 
00172         function getPossibleStarters(&$item_obj)
00173         {
00174                 foreach($item_obj->getItems() as $node)
00175                 {
00176                         switch($node['type'])
00177                         {
00178                                 case 'lm':
00179                                 case 'sahs':
00180                                 case 'svy':
00181                                 case 'tst':
00182                                         $poss_items[] = $node['ref_id'];
00183                                         break;
00184                         }
00185                 }
00186                 return $poss_items ? $poss_items : array();
00187         }
00188 
00189         function allFullfilled($user_id)
00190         {
00191                 foreach($this->getStartObjects() as $item)
00192                 {
00193                         if(!$this->isFullfilled($user_id,$item['item_ref_id']))
00194                         {
00195                                 return false;
00196                         }
00197                 }
00198                 return true;
00199         }
00200 
00201 
00202         function isFullfilled($user_id,$item_id)
00203         {
00204                 global $ilObjDataCache;
00205 
00206                 include_once './Modules/Course/classes/class.ilCourseLMHistory.php';
00207                 $lm_continue =& new ilCourseLMHistory($this->getRefId(),$user_id);
00208                 $continue_data = $lm_continue->getLMHistory();
00209 
00210                 $obj_id = $ilObjDataCache->lookupObjId($item_id);
00211                 $type = $ilObjDataCache->lookupType($obj_id);
00212                 
00213                 switch($type)
00214                 {
00215                         case 'tst':
00216                                 include_once './Modules/Test/classes/class.ilObjTestAccess.php';
00217                                 
00218                                 if(!ilObjTestAccess::_checkCondition($obj_id,'finished',''))
00219                                 {
00220                                         return false;
00221                                 }
00222                                 break;
00223                         case 'svy':
00224                                 include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php';
00225                                 if(!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id))
00226                                 {
00227                                         return false;
00228                                 }
00229                                 break;
00230                         case 'sahs':
00231                                 include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
00232                                 $completed = ilLPStatusWrapper::_getCompleted($obj_id);
00233                                 if(!in_array($user_id,$completed))
00234                                 {
00235                                         return false;
00236                                 }
00237                                 break;
00238 
00239                         default:
00240                                 if(!isset($continue_data[$item_id]))
00241                                 {
00242                                         return false;
00243                                 }
00244                 }
00245                 return true;
00246         }
00247 
00248 
00249         // PRIVATE
00250         function __read()
00251         {
00252                 global $tree,$ilDB;
00253 
00254                 $this->start_objs = array();
00255 
00256                 $query = "SELECT * FROM crs_start ".
00257                         "WHERE crs_id = ".$ilDB->quote($this->getId())." ";
00258 
00259                 $res = $this->db->query($query);
00260                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00261                 {
00262                         if($tree->isInTree($row->item_ref_id))
00263                         {
00264                                 $this->start_objs[$row->crs_start_id]['item_ref_id'] = $row->item_ref_id;
00265                         }
00266                         else
00267                         {
00268                                 $this->delete($row->item_ref_id);
00269                         }
00270                 }
00271                 return true;
00272         }
00273 
00274                 
00275 
00276 
00277 } // END class.ilObjCourseGrouping
00278 ?>

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