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

Modules/Course/classes/class.ilCourseAgreement.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 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
00024 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
00025 
00026 
00035 class ilCourseAgreement
00036 {
00037         private $db;
00038         private $user_id;
00039         private $obj_id;
00040         
00041         private $privacy;
00042         
00043         private $accepted = false;
00044         private $acceptance_time = 0;
00045         
00053         public function __construct($a_usr_id,$a_obj_id)
00054         {
00055                 global $ilDB;
00056                 
00057                 $this->db = $ilDB;
00058                 $this->user_id = $a_usr_id;
00059                 $this->obj_id = $a_obj_id;
00060                 
00061                 $this->privacy = ilPrivacySettings::_getInstance();
00062                 
00063                 if($this->privacy->confirmationRequired() or ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
00064                 {
00065                         $this->read();
00066                 }
00067         }
00068         
00077         public static function _readByObjId($a_obj_id)
00078         {
00079                 global $ilDB;
00080                 
00081                 $query = "SELECT * FROM member_agreement ".
00082                         "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00083                         
00084                 $res = $ilDB->query($query);
00085                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00086                 {
00087                         $user_data[$row->usr_id]['accepted'] = $row->accepted;
00088                         $user_data[$row->usr_id]['acceptance_time'] = $row->acceptance_time;
00089                 }
00090                 return $user_data ? $user_data : array();                                       
00091         }
00092         
00101         public static function _hasAgreementsByObjId($a_obj_id)
00102         {
00103                 global $ilDB;
00104                 
00105                 $query = "SELECT * FROM member_agreement ".
00106                         "WHERE obj_id = ".$ilDB->quote($a_obj_id)." ".
00107                         "AND accepted = 1";
00108                 
00109                 $res = $ilDB->query($query);
00110                 return $res->numRows() ? true : false;
00111         }
00112         
00121         public static function _hasAgreements()
00122         {
00123                 global $ilDB;
00124                 
00125                 $query = "SELECT * FROM member_agreement ".
00126                         "WHERE accepted = 1";
00127                 
00128                 $res = $ilDB->query($query);
00129                 return $res->numRows() ? true : false;
00130         }
00131 
00140         public static function _hasAccepted($a_usr_id,$a_obj_id)
00141         {
00142                 global $ilDB;
00143                 
00144                 $query = "SELECT accepted FROM member_agreement ".
00145                         "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
00146                         "AND obj_id = ".$ilDB->quote($a_obj_id);
00147                 $res = $ilDB->query($query);
00148                 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00149                 
00150                 return $row->accepted == 1 ? true : false;
00151         }
00152         
00153         
00162         public static function _deleteByUser($a_usr_id)
00163         {
00164                 global $ilDB;
00165                 
00166                 $query = "DELETE FROM member_agreement ".
00167                         "WHERE usr_id =".$ilDB->quote($a_usr_id)." ";
00168                 $ilDB->query($query);
00169                 
00170                 return true;
00171         }
00172         
00180         public static function _deleteByObjId($a_obj_id)
00181         {
00182                 global $ilDB;
00183                 
00184                 $query = "DELETE FROM member_agreement ".
00185                         "WHERE obj_id =".$ilDB->quote($a_obj_id)." ";
00186                 $ilDB->query($query);
00187                 
00188                 return true;
00189                 
00190         }
00191         
00200         public static function _reset()
00201         {
00202                 global $ilDB;
00203                 
00204                 $query = "UPDATE member_agreement SET accepted = 0 ";
00205                 $ilDB->query($query);
00206                 
00207                 return true;
00208         }
00209         
00217         public static function _resetContainer($a_container_id)
00218         {
00219                 global $ilDB;
00220                 
00221                 $query = "UPDATE member_agreement ".
00222                         "SET accepted = 0 ".
00223                         "WHERE obj_id = ".$ilDB->quote($a_container_id)." ";
00224                 $ilDB->query($query);
00225                 
00226                 return true;
00227         }
00235         public function setAccepted($a_status)
00236         {
00237                 $this->accepted = $a_status;
00238         }
00239         
00247         public function setAcceptanceTime($a_timest)
00248         {
00249                 $this->acceptance_time = $a_timest;
00250         }
00258         public function agreementRequired()
00259         {
00260                 if(!$this->privacy->confirmationRequired() and !ilCourseDefinedFieldDefinition::_hasFields($this->obj_id))
00261                 {
00262                         return false;
00263                 }
00264                 return $this->accepted ? false : true;
00265         }
00266         
00274         public function isAccepted()
00275         {
00276                 return (bool) $this->accepted;
00277         }
00278         
00286         public function getAcceptanceTime()
00287         {
00288                 return $this->acceptance_time;
00289         }
00290         
00297         public function save()
00298         {
00299                 $this->delete();
00300                 
00301                 $query = "INSERT INTO member_agreement ".
00302                         "SET usr_id = ".$this->db->quote($this->user_id).", ".
00303                         "obj_id = ".$this->db->quote($this->obj_id).", ".
00304                         "accepted = ".$this->db->quote((int) $this->isAccepted()).", ".
00305                         "acceptance_time = ".$this->db->quote($this->getAcceptanceTime());
00306                         
00307                 $this->db->query($query);
00308                 return true;    
00309         }
00310         
00317         public function delete()
00318         {
00319                 $query = "DELETE FROM member_agreement ".
00320                         "WHERE usr_id = ".$this->db->quote($this->user_id)." ".
00321                         "AND obj_id = ".$this->db->quote($this->obj_id);
00322                 
00323                 $this->db->query($query);
00324                 return true;                    
00325         }
00326         
00332         private function read()
00333         {
00334                 $query = "SELECT * FROM member_agreement ".
00335                         "WHERE usr_id = ".$this->db->quote($this->user_id)." ".
00336                         "AND obj_id = ".$this->db->quote($this->obj_id)." ";
00337                         
00338                 $res = $this->db->query($query);
00339                 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00340                 $this->accepted = $row->accepted;
00341                 $this->acceptance_time = $row->acceptance_time;
00342         }
00343 }
00344 ?>

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