~ubuntu-branches/ubuntu/natty/moodle/natty

« back to all changes in this revision

Viewing changes to auth/cas/CAS/CAS/PGTStorage/pgt-db.php

  • Committer: Bazaar Package Importer
  • Author(s): Tomasz Muras
  • Date: 2010-10-30 12:19:28 UTC
  • mfrom: (1.1.12 upstream) (3.1.10 squeeze)
  • Revision ID: james.westby@ubuntu.com-20101030121928-qzobi6mctpnk4dif
Tags: 1.9.9.dfsg2-2
* Added Romanian translation
* Updated Japanese translation (closes: #596820)
* Backporting security fixes from Moodle 1.9.10 (closes: #601384)
   - Updated embedded CAS to 1.1.3
   - Added patch for MDL-24523:
     clean_text() not filtering text in markdown format
   - Added patch for MDL-24810 and upgraded customized HTML Purifier to 4.2.0 
   - Added patch for MDL-24258:
     students can delete their forum posts later than $CFG->maxeditingtime 
     under certain conditions
   - Added patch for MDL-23377:
     Can't delete quiz attempts in course without enrolled students

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * @file CAS/PGTStorage/pgt-db.php
 
5
 * Basic class for PGT database storage
 
6
 */
 
7
 
 
8
/**
 
9
 * @class PGTStorageDB
 
10
 * The PGTStorageDB class is a class for PGT database storage. An instance of 
 
11
 * this class is returned by CASClient::SetPGTStorageDB().
 
12
 *
 
13
 * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
 
14
 *
 
15
 * @ingroup internalPGTStorageDB
 
16
 */
 
17
 
 
18
class PGTStorageDB extends PGTStorage
 
19
{
 
20
  /** 
 
21
   * @addtogroup internalPGTStorageDB
 
22
   * @{ 
 
23
   */
 
24
 
 
25
  /**
 
26
   * a string representing a PEAR DB URL to connect to the database. Written by
 
27
   * PGTStorageDB::PGTStorageDB(), read by getURL().
 
28
   *
 
29
   * @hideinitializer
 
30
   * @private
 
31
   */
 
32
  var $_url='';
 
33
 
 
34
  /**
 
35
   * This method returns the PEAR DB URL to use to connect to the database.
 
36
   *
 
37
   * @return a PEAR DB URL
 
38
   *
 
39
   * @private
 
40
   */
 
41
  function getURL()
 
42
    {
 
43
      return $this->_url;
 
44
    }
 
45
 
 
46
  /**
 
47
   * The handle of the connection to the database where PGT's are stored. Written by
 
48
   * PGTStorageDB::init(), read by getLink().
 
49
   *
 
50
   * @hideinitializer
 
51
   * @private
 
52
   */
 
53
  var $_link = null;
 
54
 
 
55
  /**
 
56
   * This method returns the handle of the connection to the database where PGT's are 
 
57
   * stored.
 
58
   *
 
59
   * @return a handle of connection.
 
60
   *
 
61
   * @private
 
62
   */
 
63
  function getLink()
 
64
    {
 
65
      return $this->_link;
 
66
    }
 
67
 
 
68
  /**
 
69
   * The name of the table where PGT's are stored. Written by 
 
70
   * PGTStorageDB::PGTStorageDB(), read by getTable().
 
71
   *
 
72
   * @hideinitializer
 
73
   * @private
 
74
   */
 
75
  var $_table = '';
 
76
 
 
77
  /**
 
78
   * This method returns the name of the table where PGT's are stored.
 
79
   *
 
80
   * @return the name of a table.
 
81
   *
 
82
   * @private
 
83
   */
 
84
  function getTable()
 
85
    {
 
86
      return $this->_table;
 
87
    }
 
88
 
 
89
  // ########################################################################
 
90
  //  DEBUGGING
 
91
  // ########################################################################
 
92
  
 
93
  /**
 
94
   * This method returns an informational string giving the type of storage
 
95
   * used by the object (used for debugging purposes).
 
96
   *
 
97
   * @return an informational string.
 
98
   * @public
 
99
   */
 
100
  function getStorageType()
 
101
    {
 
102
      return "database";
 
103
    }
 
104
 
 
105
  /**
 
106
   * This method returns an informational string giving informations on the
 
107
   * parameters of the storage.(used for debugging purposes).
 
108
   *
 
109
   * @public
 
110
   */
 
111
  function getStorageInfo()
 
112
    {
 
113
      return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\'';
 
114
    }
 
115
 
 
116
  // ########################################################################
 
117
  //  CONSTRUCTOR
 
118
  // ########################################################################
 
119
  
 
120
  /**
 
121
   * The class constructor, called by CASClient::SetPGTStorageDB().
 
122
   *
 
123
   * @param $cas_parent the CASClient instance that creates the object.
 
124
   * @param $user the user to access the data with
 
125
   * @param $password the user's password
 
126
   * @param $database_type the type of the database hosting the data
 
127
   * @param $hostname the server hosting the database
 
128
   * @param $port the port the server is listening on
 
129
   * @param $database the name of the database
 
130
   * @param $table the name of the table storing the data
 
131
   *
 
132
   * @public
 
133
   */
 
134
  function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table)
 
135
    {
 
136
      phpCAS::traceBegin();
 
137
 
 
138
      // call the ancestor's constructor
 
139
      $this->PGTStorage($cas_parent);
 
140
 
 
141
      if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE;
 
142
      if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME;
 
143
      if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT;
 
144
      if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE;
 
145
      if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE;
 
146
 
 
147
      // build and store the PEAR DB URL
 
148
      $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database;
 
149
 
 
150
      // XXX should use setURL and setTable
 
151
      phpCAS::traceEnd();
 
152
    }
 
153
  
 
154
  // ########################################################################
 
155
  //  INITIALIZATION
 
156
  // ########################################################################
 
157
  
 
158
  /**
 
159
   * This method is used to initialize the storage. Halts on error.
 
160
   *
 
161
   * @public
 
162
   */
 
163
  function init()
 
164
    {
 
165
      phpCAS::traceBegin();
 
166
      // if the storage has already been initialized, return immediatly
 
167
      if ( $this->isInitialized() )
 
168
                return;
 
169
      // call the ancestor's method (mark as initialized)
 
170
      parent::init();
 
171
      
 
172
          //include phpDB library (the test was introduced in release 0.4.8 for 
 
173
          //the integration into Tikiwiki).
 
174
          if (!class_exists('DB')) {
 
175
                include_once('DB.php');
 
176
          }
 
177
 
 
178
      // try to connect to the database
 
179
      $this->_link = DB::connect($this->getURL());
 
180
      if ( DB::isError($this->_link) ) {
 
181
        phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')');
 
182
      }
 
183
      var_dump($this->_link);
 
184
      phpCAS::traceBEnd();
 
185
    }
 
186
 
 
187
  /** @} */
 
188
}
 
189
 
 
190
?>
 
 
b'\\ No newline at end of file'