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

Modules/Course/classes/Export/class.ilCourseUserData.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 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 
00032 class ilCourseUserData
00033 {
00034         private $db;
00035         private $user_id;
00036         private $field_id;
00037         private $value;
00038         
00039         
00048         public function __construct($a_user_id,$a_field_id = 0)
00049         {
00050                 global $ilDB;
00051                 
00052                 $this->db = $ilDB;
00053                 $this->user_id = $a_user_id;
00054                 $this->field_id = $a_field_id;
00055                 
00056                 if($this->field_id)
00057                 {
00058                         $this->read();
00059                 }
00060         }
00061         
00070         public static function _getValuesByObjId($a_obj_id)
00071         {
00072                 global $ilDB;
00073                 
00074                 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
00075                 $field_ids = ilCourseDefinedFieldDefinition::_getFieldIds($a_obj_id);
00076                 if(!count($field_ids))
00077                 {
00078                         return array();
00079                 }
00080                 $where = ("WHERE field_id IN (".implode(",",ilUtil::quoteArray($field_ids)).") ");
00081                 
00082                 $query = "SELECT * FROM crs_user_data ".
00083                         $where;
00084                 
00085                 $res = $ilDB->query($query);
00086                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00087                 {
00088                         $user_data[$row->usr_id][$row->field_id] = $row->value;
00089                 }
00090                 
00091                 return $user_data ? $user_data : array();
00092         }
00093         
00105         public static function _checkRequired($a_usr_id,$a_obj_id)
00106         {
00107                 global $ilDB;
00108 
00109                 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
00110                 $required = ilCourseDefinedFieldDefinition::_getRequiredFieldIds($a_obj_id);
00111                 if(!count($required))
00112                 {
00113                         return true;
00114                 }
00115                 
00116                 $and = ("AND field_id IN (".implode(",",ilUtil::quoteArray($required)).")");
00117                 $query = "SELECT COUNT(*) as num_entries FROM crs_user_data ".
00118                         "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
00119                         "AND value != '' ".
00120                         $and;
00121                 $res = $ilDB->query($query);
00122                 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00123                 
00124                 return $row->num_entries == count($required);
00125         }
00126         
00135         public static function _deleteByUser($a_user_id)
00136         {
00137                 global $ilDB;
00138                 
00139                 $query = "DELETE FROM crs_user_data ".
00140                         "WHERE usr_id = ".$ilDB->quote($a_user_id);
00141                 $ilDB->query($query);
00142                                         
00143         }
00144         
00152         public static function _deleteByField($a_field_id)
00153         {
00154                 global $ilDB;
00155                 
00156                 $query = "DELETE FROM crs_user_data ".
00157                         "WHERE field_id = ".$ilDB->quote($a_field_id);
00158                 $ilDB->query($query);
00159         }
00160         
00161         public function setValue($a_value)
00162         {
00163                 $this->value = $a_value;
00164         }
00165         public function getValue()
00166         {
00167                 return $this->value;
00168         }
00169         
00176         public function update()
00177         {
00178                 $this->delete();
00179                 $this->create();        
00180         }
00181         
00188         public function delete()
00189         {
00190                 $query = "DELETE FROM crs_user_data ".
00191                         "WHERE usr_id = ".$this->db->quote($this->user_id)." ".
00192                         "AND field_id = ".$this->db->quote($this->field_id);
00193                 $this->db->query($query);
00194         }
00195         
00202         public function create()
00203         {
00204                 $query = "INSERT INTO crs_user_data SET ".
00205                         "value = ".$this->db->quote($this->getValue()).", ".
00206                         "usr_id = ".$this->db->quote($this->user_id).", ".
00207                         "field_id = ".$this->db->quote($this->field_id)." ";
00208                 $this->db->query($query);
00209         }
00210 
00216         private function read()
00217         {
00218                 $query = "SELECT * FROM crs_user_data ".
00219                         "WHERE usr_id = ".$this->db->quote($this->user_id)." ".
00220                         "AND field_id = ".$this->db->quote($this->field_id);
00221                 $res = $this->db->query($query);
00222                 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00223 
00224                 $this->setValue($row->value);                   
00225                         
00226         }
00227 }
00228 
00229 
00230 ?>

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