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

Modules/Course/classes/class.ilCourseObjective.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 ilCourseObjective
00035 {
00036         var $db = null;
00037 
00038         var $course_obj = null;
00039         var $objective_id = null;
00040         
00041         function ilCourseObjective(&$course_obj,$a_objective_id = 0)
00042         {
00043                 global $ilDB;
00044 
00045                 $this->db =& $ilDB;
00046                 $this->course_obj =& $course_obj;
00047 
00048                 $this->objective_id = $a_objective_id;
00049                 if($this->objective_id)
00050                 {
00051                         $this->__read();
00052                 }
00053                 $this->__cleanStructure();
00054         }
00055         
00064         public static function _lookupContainerIdByObjectiveId($a_objective_id)
00065         {
00066                 global $ilDB;
00067                 
00068                 $query = "SELECT crs_id FROM crs_objectives ".
00069                         "WHERE objective_id = ".$ilDB->quote($a_objective_id);
00070                 $res = $ilDB->query($query);
00071                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00072                 {
00073                         return $row->crs_id;
00074                 }
00075                 return false;
00076         }
00077         
00086         public function ilClone($a_target_id,$a_copy_id)
00087         {
00088                 global $ilLog;
00089                 
00090                 $ilLog->write(__METHOD__.': Start cloning learning objectives...');
00091                 
00092                 $query = "SELECT * FROM crs_objectives ".
00093                         "WHERE crs_id  = ".$this->db->quote($this->course_obj->getId()).
00094                         "ORDER BY position ";
00095                 $res = $this->db->query($query);
00096                 if(!$res->numRows())
00097                 {
00098                         $ilLog->write(__METHOD__.': ... no objectives found.');
00099                         return true;
00100                 }
00101                 
00102                 if(!is_object($new_course = ilObjectFactory::getInstanceByRefId($a_target_id,false)))
00103                 {
00104                         $ilLog->write(__METHOD__.': Cannot init new course object.');
00105                         return true;
00106                 }
00107                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00108                 {
00109                         $new_objective = new ilCourseObjective($new_course);
00110                         $new_objective->setTitle($row->title);
00111                         $new_objective->setDescription($row->description);
00112                         $objective_id = $new_objective->add();
00113                         $ilLog->write(__METHOD__.': Added new objective nr: '.$objective_id);
00114                         
00115                         // Clone crs_objective_tst entries
00116                         include_once('Modules/Course/classes/class.ilCourseObjectiveQuestion.php');
00117                         $objective_qst = new ilCourseObjectiveQuestion($row->objective_id);
00118                         $objective_qst->cloneDependencies($objective_id,$a_copy_id);
00119 
00120                         $ilLog->write(__METHOD__.': Finished objective question dependencies: '.$objective_id);
00121                         
00122                         // Clone crs_objective_lm entries (assigned course materials)
00123                         include_once('Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
00124                         $objective_material = new ilCourseObjectiveMaterials($row->objective_id);
00125                         $objective_material->cloneDependencies($objective_id,$a_copy_id);
00126                 }
00127                 $ilLog->write(__METHOD__.': Finished cloning objectives.');
00128         }
00129 
00130         function setTitle($a_title)
00131         {
00132                 $this->title = $a_title;
00133         }
00134         function getTitle()
00135         {
00136                 return $this->title;
00137         }
00138         function setDescription($a_description)
00139         {
00140                 $this->description = $a_description;
00141         }
00142         function getDescription()
00143         {
00144                 return $this->description;
00145         }
00146         function setObjectiveId($a_objective_id)
00147         {
00148                 $this->objective_id = $a_objective_id;
00149         }
00150         function getObjectiveId()
00151         {
00152                 return $this->objective_id;
00153         }
00154 
00155         function add()
00156         {
00157                 global $ilDB;
00158                 
00159                 $query = "INSERT INTO crs_objectives ".
00160                         "SET crs_id = ".$ilDB->quote($this->course_obj->getId()).", ".
00161                         "title = ".$ilDB->quote($this->getTitle()).", ".
00162                         "description = ".$ilDB->quote($this->getDescription()).", ".
00163                         "position = ".$ilDB->quote($this->__getLastPosition() + 1).", ".
00164                         "created = ".$ilDB->quote(time());
00165 
00166                 $this->db->query($query);
00167                 
00168                 return $this->objective_id = $this->db->getLastInsertId();
00169         }
00170 
00171         function update()
00172         {
00173                 global $ilDB;
00174                 
00175                 $query = "UPDATE crs_objectives ".
00176                         "SET title = ".$ilDB->quote($this->getTitle()).", ".
00177                         "description = ".$ilDB->quote($this->getDescription())." ".
00178                         "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00179                         "AND crs_id = ".$ilDB->quote($this->course_obj->getId())."";
00180                 
00181                 $this->db->query($query);
00182                 
00183                 return true;
00184         }
00185         
00186         function delete()
00187         {
00188                 global $ilDB;
00189                 
00190                 include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
00191 
00192                 $tmp_obj_qst =& new ilCourseObjectiveQuestion($this->getObjectiveId());
00193                 $tmp_obj_qst->deleteAll();
00194 
00195                 include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
00196 
00197                 $tmp_obj_lm =& new ilCourseObjectiveMaterials($this->getObjectiveId());
00198                 $tmp_obj_lm->deleteAll();
00199 
00200 
00201                 $query = "DELETE FROM crs_objectives ".
00202                         "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId())." ".
00203                         "AND objective_id = ".$ilDB->quote($this->getObjectiveId())." ";
00204 
00205                 $this->db->query($query);
00206 
00207                 $this->__updateTop();
00208                 
00209                 return true;
00210         }
00211 
00212         function moveUp()
00213         {
00214                 global $ilDB;
00215                 
00216                 if(!$this->getObjectiveId())
00217                 {
00218                         return false;
00219                 }
00220                 // Stop if position is first
00221                 if($this->__getPosition() == 1)
00222                 {
00223                         return false;
00224                 }
00225 
00226                 $query = "UPDATE crs_objectives ".
00227                         "SET position = position + 1 ".
00228                         "WHERE position = ".$ilDB->quote($this->__getPosition() - 1)." ".
00229                         "AND crs_id = ".$ilDB->quote($this->course_obj->getId())." ";
00230                 
00231                 $this->db->query($query);
00232                 
00233                 $query = "UPDATE crs_objectives ".
00234                         "SET position = position - 1 ".
00235                         "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00236                         "AND crs_id = ".$ilDB->quote($this->course_obj->getId())." ";
00237 
00238                 $this->db->query($query);
00239 
00240                 $this->__read();
00241 
00242                 return true;
00243         }
00244 
00245         function moveDown()
00246         {
00247                 global $ilDB;
00248                 
00249                 if(!$this->getObjectiveId())
00250                 {
00251                         return false;
00252                 }
00253                 // Stop if position is last
00254                 if($this->__getPosition() == $this->__getLastPosition())
00255                 {
00256                         return false;
00257                 }
00258                 
00259                 $query = "UPDATE crs_objectives ".
00260                         "SET position = position - 1 ".
00261                         "WHERE position = ".$ilDB->quote($this->__getPosition() + 1)." ".
00262                         "AND crs_id = ".$ilDB->quote($this->course_obj->getId())." ";
00263 
00264                 $this->db->query($query);
00265                 
00266                 $query = "UPDATE crs_objectives ".
00267                         "SET position = position + 1 ".
00268                         "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId())." ".
00269                         "AND crs_id = ".$ilDB->quote($this->course_obj->getId())." ";
00270 
00271                 $this->db->query($query);
00272 
00273                 $this->__read();
00274 
00275                 return true;
00276         }
00277 
00278         // PRIVATE
00279         function __setPosition($a_position)
00280         {
00281                 $this->position = $a_position;
00282         }
00283         function __getPosition()
00284         {
00285                 return $this->position;
00286         }
00287         function __setCreated($a_created)
00288         {
00289                 $this->created = $a_created;
00290         }
00291         function __getCreated()
00292         {
00293                 return $this->created;
00294         }
00295 
00296 
00297         function __read()
00298         {
00299                 global $ilDB;
00300                 
00301                 if($this->getObjectiveId())
00302                 {
00303                         $query = "SELECT * FROM crs_objectives ".
00304                                 "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId())." ".
00305                                 "AND objective_id = ".$ilDB->quote($this->getObjectiveId())." ";
00306                                 
00307 
00308                         $res = $this->db->query($query);
00309                         while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00310                         {
00311                                 $this->setObjectiveId($row->objective_id);
00312                                 $this->setTitle($row->title);
00313                                 $this->setDescription($row->description);
00314                                 $this->__setPosition($row->position);
00315                                 $this->__setCreated($row->created);
00316                         }
00317                         return true;
00318                 }
00319                 return false;
00320         }
00321 
00322         function __getOrderColumn()
00323         {
00324                 switch($this->course_obj->getOrderType())
00325                 {
00326                         case $this->course_obj->SORT_MANUAL:
00327                                 return 'ORDER BY position';
00328 
00329                         case $this->course_obj->SORT_TITLE:
00330                                 return 'ORDER BY title';
00331 
00332                         case $this->course_obj->SORT_ACTIVATION:
00333                                 return 'ORDER BY create';
00334                 }
00335                 return false;
00336         }
00337 
00338         function __updateTop()
00339         {
00340                 global $ilDB;
00341                 
00342                 $query = "UPDATE crs_objectives ".
00343                         "SET position = position - 1 ".
00344                         "WHERE position > ".$ilDB->quote($this->__getPosition())." ".
00345                         "AND crs_id = ".$ilDB->quote($this->course_obj->getId())." ";
00346 
00347                 $this->db->query($query);
00348 
00349                 return true;
00350         }
00351 
00352         function __getLastPosition()
00353         {
00354                 global $ilDB;
00355                 
00356                 $query = "SELECT MAX(position) AS pos FROM crs_objectives ".
00357                         "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId())." ";
00358 
00359                 $res = $this->db->query($query);
00360                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00361                 {
00362                         return $row->pos;
00363                 }
00364                 return 0;
00365         }
00366 
00367         // STATIC
00368         function _getObjectiveIds($course_id)
00369         {
00370                 global $ilDB;
00371 
00372                 $query = "SELECT objective_id FROM crs_objectives ".
00373                         "WHERE crs_id = ".$ilDB->quote($course_id)." ".
00374                         "ORDER BY position";
00375 
00376                 $res = $ilDB->query($query);
00377                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00378                 {
00379                         $ids[] = $row->objective_id;
00380                 }
00381 
00382                 return $ids ? $ids : array();
00383         }
00384 
00385         function _deleteAll($course_id)
00386         {
00387                 global $ilDB;
00388 
00389                 $ids = ilCourseObjective::_getObjectiveIds($course_id);
00390                 
00391                 if(!count($ids))
00392                 {
00393                         return true;
00394                 }
00395                 $in = "IN (";
00396                 $in .= implode(",",ilUtil::quoteArray($ids));
00397                 $in .= ")";
00398 
00399                 $query = "DELETE FROM crs_objective_lm WHERE objective_id ".$in;
00400                 $ilDB->query($query);
00401 
00402                 $query = "DELETE FROM crs_objective_tst WHERE objective_id ".$in;
00403                 $ilDB->query($query);
00404                 
00405                 $query = "DELETE FROM crs_objective_qst WHERE objective_id ".$in;
00406                 $ilDB->query($query);
00407                 
00408                 $query = "DELETE FROM crs_objectives WHERE crs_id = ".$ilDB->quote($course_id);
00409                 $ilDB->query($query);
00410 
00411                 return true;
00412         }
00413 
00414         function __cleanStructure()
00415         {
00416                 global $ilDB;
00417                 
00418                 $query = "SELECT * FROM crs_objectives ".
00419                         "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId())." ".
00420                         "ORDER BY position";
00421 
00422                 $res = $this->db->query($query);
00423 
00424                 $counter = 0;
00425                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00426                 {
00427                         if($row->position != ++$counter)
00428                         {
00429                                 $query = "UPDATE crs_objectives SET ".
00430                                         "position = ".$ilDB->quote($counter)." ".
00431                                         "WHERE objective_id = ".$ilDB->quote($row->objective_id)." ";
00432 
00433                                 $this->db->query($query);
00434                         }
00435                 }
00436                 return true;
00437         }
00438 
00439 }
00440 ?>

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