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

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 
00035 class ilCourseObjective
00036 {
00037         var $db = null;
00038 
00039         var $course_obj = null;
00040         var $objective_id = null;
00041         
00042         function ilCourseObjective(&$course_obj,$a_objective_id = 0)
00043         {
00044                 global $ilDB;
00045 
00046                 $this->db =& $ilDB;
00047                 $this->course_obj =& $course_obj;
00048 
00049                 $this->objective_id = $a_objective_id;
00050                 if($this->objective_id)
00051                 {
00052                         $this->__read();
00053                 }
00054                 $this->__cleanStructure();
00055         }
00056 
00057         function setTitle($a_title)
00058         {
00059                 $this->title = $a_title;
00060         }
00061         function getTitle()
00062         {
00063                 return $this->title;
00064         }
00065         function setDescription($a_description)
00066         {
00067                 $this->description = $a_description;
00068         }
00069         function getDescription()
00070         {
00071                 return $this->description;
00072         }
00073         function setObjectiveId($a_objective_id)
00074         {
00075                 $this->objective_id = $a_objective_id;
00076         }
00077         function getObjectiveId()
00078         {
00079                 return $this->objective_id;
00080         }
00081 
00082         function add()
00083         {
00084                 $query = "INSERT INTO crs_objectives ".
00085                         "SET crs_id = '".$this->course_obj->getId()."', ".
00086                         "title = '".ilUtil::prepareDBString($this->getTitle())."', ".
00087                         "description = '".ilUtil::prepareDBString($this->getDescription())."', ".
00088                         "position = '".($this->__getLastPosition() + 1)."', ".
00089                         "created = '".time()."'";
00090 
00091                 $this->db->query($query);
00092 
00093                 return true;
00094         }
00095 
00096         function update()
00097         {
00098                 $query = "UPDATE crs_objectives ".
00099                         "SET title = '".ilUtil::prepareDBString($this->getTitle())."', ".
00100                         "description = '".ilUtil::prepareDBString($this->getDescription())."' ".
00101                         "WHERE objective_id = '".$this->getObjectiveId()."' ".
00102                         "AND crs_id = '".$this->course_obj->getId()."'";
00103                 
00104                 $this->db->query($query);
00105                 
00106                 return true;
00107         }
00108         
00109         function delete()
00110         {
00111                 include_once './course/classes/class.ilCourseObjectiveQuestion.php';
00112 
00113                 $tmp_obj_qst =& new ilCourseObjectiveQuestion($this->getObjectiveId());
00114                 $tmp_obj_qst->deleteAll();
00115 
00116                 include_once './course/classes/class.ilCourseObjectiveLM.php';
00117 
00118                 $tmp_obj_lm =& new ilCourseObjectiveLM($this->getObjectiveId());
00119                 $tmp_obj_lm->deleteAll();
00120 
00121 
00122                 $query = "DELETE FROM crs_objectives ".
00123                         "WHERE crs_id = '".$this->course_obj->getId()."' ".
00124                         "AND objective_id = '".$this->getObjectiveId()."'";
00125 
00126                 $this->db->query($query);
00127 
00128                 $this->__updateTop();
00129                 
00130                 return true;
00131         }
00132 
00133         function moveUp()
00134         {
00135                 if(!$this->getObjectiveId())
00136                 {
00137                         return false;
00138                 }
00139                 // Stop if position is first
00140                 if($this->__getPosition() == 1)
00141                 {
00142                         return false;
00143                 }
00144 
00145                 $query = "UPDATE crs_objectives ".
00146                         "SET position = position + 1 ".
00147                         "WHERE position = '".($this->__getPosition() - 1)."' ".
00148                         "AND crs_id = '".$this->course_obj->getId()."'";
00149                 
00150                 $this->db->query($query);
00151                 
00152                 $query = "UPDATE crs_objectives ".
00153                         "SET position = position - 1 ".
00154                         "WHERE objective_id = '".$this->getObjectiveId()."' ".
00155                         "AND crs_id = '".$this->course_obj->getId()."'";
00156 
00157                 $this->db->query($query);
00158 
00159                 $this->__read();
00160 
00161                 return true;
00162         }
00163 
00164         function moveDown()
00165         {
00166                 if(!$this->getObjectiveId())
00167                 {
00168                         return false;
00169                 }
00170                 // Stop if position is last
00171                 if($this->__getPosition() == $this->__getLastPosition())
00172                 {
00173                         return false;
00174                 }
00175                 
00176                 $query = "UPDATE crs_objectives ".
00177                         "SET position = position - 1 ".
00178                         "WHERE position = '".($this->__getPosition() + 1)."' ".
00179                         "AND crs_id = '".$this->course_obj->getId()."'";
00180 
00181                 $this->db->query($query);
00182                 
00183                 $query = "UPDATE crs_objectives ".
00184                         "SET position = position + 1 ".
00185                         "WHERE objective_id = '".$this->getObjectiveId()."' ".
00186                         "AND crs_id = '".$this->course_obj->getId()."'";
00187 
00188                 $this->db->query($query);
00189 
00190                 $this->__read();
00191 
00192                 return true;
00193         }
00194 
00195         // PRIVATE
00196         function __setPosition($a_position)
00197         {
00198                 $this->position = $a_position;
00199         }
00200         function __getPosition()
00201         {
00202                 return $this->position;
00203         }
00204         function __setCreated($a_created)
00205         {
00206                 $this->created = $a_created;
00207         }
00208         function __getCreated()
00209         {
00210                 return $this->created;
00211         }
00212 
00213 
00214         function __read()
00215         {
00216                 if($this->getObjectiveId())
00217                 {
00218                         $query = "SELECT * FROM crs_objectives ".
00219                                 "WHERE crs_id = '".$this->course_obj->getId()."' ".
00220                                 "AND objective_id = '".$this->getObjectiveId()."'";
00221                                 
00222 
00223                         $res = $this->db->query($query);
00224                         while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00225                         {
00226                                 $this->setObjectiveId($row->objective_id);
00227                                 $this->setTitle($row->title);
00228                                 $this->setDescription($row->description);
00229                                 $this->__setPosition($row->position);
00230                                 $this->__setCreated($row->created);
00231                         }
00232                         return true;
00233                 }
00234                 return false;
00235         }
00236 
00237         function __getOrderColumn()
00238         {
00239                 switch($this->course_obj->getOrderType())
00240                 {
00241                         case $this->course_obj->SORT_MANUAL:
00242                                 return 'ORDER BY position';
00243 
00244                         case $this->course_obj->SORT_TITLE:
00245                                 return 'ORDER BY title';
00246 
00247                         case $this->course_obj->SORT_ACTIVATION:
00248                                 return 'ORDER BY create';
00249                 }
00250                 return false;
00251         }
00252 
00253         function __updateTop()
00254         {
00255                 $query = "UPDATE crs_objectives ".
00256                         "SET position = position - 1 ".
00257                         "WHERE position > '".$this->__getPosition()."' ".
00258                         "AND crs_id = '".$this->course_obj->getId()."'";
00259 
00260                 $this->db->query($query);
00261 
00262                 return true;
00263         }
00264 
00265         function __getLastPosition()
00266         {
00267                 $query = "SELECT MAX(position) AS pos FROM crs_objectives ".
00268                         "WHERE crs_id = '".$this->course_obj->getId()."'";
00269 
00270                 $res = $this->db->query($query);
00271                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00272                 {
00273                         return $row->pos;
00274                 }
00275                 return 0;
00276         }
00277 
00278         // STATIC
00279         function _getObjectiveIds($course_id)
00280         {
00281                 global $ilDB;
00282 
00283                 $query = "SELECT objective_id FROM crs_objectives ".
00284                         "WHERE crs_id = '".$course_id."' ".
00285                         "ORDER BY position";
00286 
00287                 $res = $ilDB->query($query);
00288                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00289                 {
00290                         $ids[] = $row->objective_id;
00291                 }
00292 
00293                 return $ids ? $ids : array();
00294         }
00295 
00296         function _deleteAll($course_id)
00297         {
00298                 global $ilDB;
00299 
00300                 $ids = ilCourseObjective::_getObjectiveIds($course_id);
00301                 
00302                 if(!count($ids))
00303                 {
00304                         return true;
00305                 }
00306                 $in = "IN ('";
00307                 $in .= implode("','",$ids);
00308                 $in .= "')";
00309 
00310                 $query = "DELETE FROM crs_objective_lm WHERE objective_id ".$in;
00311                 $ilDB->query($query);
00312 
00313                 $query = "DELETE FROM crs_objective_tst WHERE objective_id ".$in;
00314                 $ilDB->query($query);
00315                 
00316                 $query = "DELETE FROM crs_objective_qst WHERE objective_id ".$in;
00317                 $ilDB->query($query);
00318 
00319                 return true;
00320         }
00321 
00322         function __cleanStructure()
00323         {
00324                 $query = "SELECT * FROM crs_objectives ".
00325                         "WHERE crs_id = '".$this->course_obj->getId()."' ".
00326                         "ORDER BY position";
00327 
00328                 $res = $this->db->query($query);
00329 
00330                 $counter = 0;
00331                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00332                 {
00333                         if($row->position != ++$counter)
00334                         {
00335                                 $query = "UPDATE crs_objectives SET ".
00336                                         "position = '".$counter."' ".
00337                                         "WHERE objective_id = '".$row->objective_id."'";
00338 
00339                                 $this->db->query($query);
00340                         }
00341                 }
00342                 return true;
00343         }
00344 
00345 }
00346 ?>

Generated on Fri Dec 13 2013 13:52:10 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1