ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilCalendarAuthenticationToken Class Reference

Handles calendar authentication tokens for external calendar subscriptions. More...

+ Collaboration diagram for ilCalendarAuthenticationToken:

Public Member Functions

 __construct ($a_user_id, $a_token='')
 Constructor. More...
 
 getSelectionType ()
 get selection type for key More...
 
 getUserId ()
 Get current user. More...
 
 setSelectionType ($a_type)
 set selection type More...
 
 setCalendar ($a_cal)
 set calendar id More...
 
 getCalendar ()
 
 setIcal ($ical)
 
 getIcal ()
 get stored ical More...
 
 getToken ()
 get token More...
 
 storeIcal ()
 store ical More...
 
 isIcalExpired ()
 Check if cache is disabled or expired. More...
 
 add ()
 Add token. More...
 

Static Public Member Functions

static lookupAuthToken ($a_user_id, $a_selection, $a_calendar=0)
 
static lookupUser ($a_token)
 Lookup user by hash. More...
 

Data Fields

const SELECTION_NONE = 0
 
const SELECTION_PD = 1
 
const SELECTION_CATEGORY = 2
 
const SELECTION_CALENDAR = 3
 

Protected Member Functions

 createToken ()
 Create a new token. More...
 
 read ()
 Read key. More...
 

Private Attributes

 $user = null
 
 $token = ''
 
 $selection_type = 0
 
 $calendar = 0
 
 $ical = null
 
 $ical_ctime = null
 

Detailed Description

Handles calendar authentication tokens for external calendar subscriptions.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilCalendarAuthenticationToken.php.

Constructor & Destructor Documentation

◆ __construct()

ilCalendarAuthenticationToken::__construct (   $a_user_id,
  $a_token = '' 
)

Constructor.

Parameters
int$a_user_id
string$a_hash
Returns
ilCalendarAuthenticationKey

Definition at line 34 of file class.ilCalendarAuthenticationToken.php.

35 {
36 $this->user = $a_user_id;
37 $this->token = $a_token;
38
39 $this->read();
40 }
user()
Definition: user.php:4

References read(), and user().

+ Here is the call graph for this function:

Member Function Documentation

◆ add()

ilCalendarAuthenticationToken::add ( )

Add token.

Returns

Definition at line 193 of file class.ilCalendarAuthenticationToken.php.

194 {
195 global $DIC;
196
197 $ilDB = $DIC['ilDB'];
198
199 $this->createToken();
200
201 $query = "INSERT INTO cal_auth_token (user_id,hash,selection,calendar) " .
202 "VALUES ( " .
203 $ilDB->quote($this->getUserId(), 'integer') . ', ' .
204 $ilDB->quote($this->getToken(), 'text') . ', ' .
205 $ilDB->quote($this->getSelectionType(), 'integer') . ', ' .
206 $ilDB->quote($this->getCalendar(), 'integer') . ' ' .
207 ')';
208 $ilDB->manipulate($query);
209
210 return $this->getToken();
211 }
$query
global $ilDB
$DIC
Definition: xapitoken.php:46

References $DIC, $ilDB, $query, createToken(), getCalendar(), getSelectionType(), getToken(), and getUserId().

+ Here is the call graph for this function:

◆ createToken()

ilCalendarAuthenticationToken::createToken ( )
protected

Create a new token.

Returns

Definition at line 217 of file class.ilCalendarAuthenticationToken.php.

218 {
219 $random = new \ilRandom();
220 $this->token = md5($this->getUserId() . $this->getSelectionType() . $random->int());
221 }

References getSelectionType(), and getUserId().

Referenced by add().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCalendar()

ilCalendarAuthenticationToken::getCalendar ( )

Definition at line 118 of file class.ilCalendarAuthenticationToken.php.

References $calendar.

Referenced by add().

+ Here is the caller graph for this function:

◆ getIcal()

ilCalendarAuthenticationToken::getIcal ( )

get stored ical

Returns

Definition at line 132 of file class.ilCalendarAuthenticationToken.php.

References $ical.

Referenced by storeIcal().

+ Here is the caller graph for this function:

◆ getSelectionType()

ilCalendarAuthenticationToken::getSelectionType ( )

get selection type for key

Returns
int selection type

Definition at line 83 of file class.ilCalendarAuthenticationToken.php.

References $selection_type.

Referenced by add(), and createToken().

+ Here is the caller graph for this function:

◆ getToken()

ilCalendarAuthenticationToken::getToken ( )

get token

Returns

Definition at line 142 of file class.ilCalendarAuthenticationToken.php.

References $token.

Referenced by add(), read(), and storeIcal().

+ Here is the caller graph for this function:

◆ getUserId()

ilCalendarAuthenticationToken::getUserId ( )

Get current user.

Returns
int user

Definition at line 93 of file class.ilCalendarAuthenticationToken.php.

References $user.

Referenced by add(), createToken(), read(), and storeIcal().

+ Here is the caller graph for this function:

◆ isIcalExpired()

ilCalendarAuthenticationToken::isIcalExpired ( )

Check if cache is disabled or expired.

Returns

Definition at line 174 of file class.ilCalendarAuthenticationToken.php.

175 {
176 return true;
177
178 include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
179
180 if (!ilCalendarSettings::_getInstance()->isSynchronisationCacheEnabled()) {
181 return true;
182 }
183 if (!ilCalendarSettings::_getInstance()->getSynchronisationCacheMinutes()) {
184 return true;
185 }
186 return time() > ($this->ical_ctime + 60 * ilCalendarSettings::_getInstance()->getSynchronisationCacheMinutes());
187 }
static _getInstance()
get singleton instance

References ilCalendarSettings\_getInstance().

+ Here is the call graph for this function:

◆ lookupAuthToken()

static ilCalendarAuthenticationToken::lookupAuthToken (   $a_user_id,
  $a_selection,
  $a_calendar = 0 
)
static

Definition at line 42 of file class.ilCalendarAuthenticationToken.php.

43 {
44 global $DIC;
45
46 $ilDB = $DIC['ilDB'];
47
48 $query = "SELECT * FROM cal_auth_token " .
49 "WHERE user_id = " . $ilDB->quote($a_user_id, 'integer') . ' ' .
50 "AND selection = " . $ilDB->quote($a_selection, 'integer') . ' ' .
51 "AND calendar = " . $ilDB->quote($a_calendar, 'integer');
52 $res = $ilDB->query($query);
53 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
54 return $row->hash;
55 }
56 return false;
57 }
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilCalendarSubscriptionGUI\createToken().

+ Here is the caller graph for this function:

◆ lookupUser()

static ilCalendarAuthenticationToken::lookupUser (   $a_token)
static

Lookup user by hash.

Parameters
object$a_token
Returns

Definition at line 64 of file class.ilCalendarAuthenticationToken.php.

65 {
66 global $DIC;
67
68 $ilDB = $DIC['ilDB'];
69
70 $query = "SELECT * FROM cal_auth_token " .
71 "WHERE hash = " . $ilDB->quote($a_token, 'text');
72 $res = $ilDB->query($query);
73 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
74 return $row->user_id;
75 }
76 return 0;
77 }

References $DIC, $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilCalendarRemoteAccessHandler\initTokenHandler().

+ Here is the caller graph for this function:

◆ read()

ilCalendarAuthenticationToken::read ( )
protected

Read key.

Returns

Definition at line 227 of file class.ilCalendarAuthenticationToken.php.

228 {
229 global $DIC;
230
231 $ilDB = $DIC['ilDB'];
232
233 if (!$this->getToken()) {
234 $query = "SELECT * FROM cal_auth_token " .
235 "WHERE user_id = " . $ilDB->quote($this->getUserId(), 'integer');
236 } else {
237 $query = 'SELECT * FROM cal_auth_token ' .
238 'WHERE user_id = ' . $ilDB->quote($this->getUserId(), 'integer') . ' ' .
239 'AND hash = ' . $ilDB->quote($this->getToken(), 'text');
240 }
241
242 $res = $ilDB->query($query);
243 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
244 $this->token = $row->hash;
245 $this->selection_type = $row->selection;
246 $this->calendar = $row->calendar;
247 $this->ical = $row->ical;
248 $this->ical_ctime = $row->c_time;
249 }
250 return true;
251 }
calendar()
Definition: calendar.php:2

References $DIC, $ilDB, $query, $res, calendar(), ilDBConstants\FETCHMODE_OBJECT, getToken(), and getUserId().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCalendar()

ilCalendarAuthenticationToken::setCalendar (   $a_cal)

set calendar id

Parameters
object$a_cal
Returns

Definition at line 113 of file class.ilCalendarAuthenticationToken.php.

114 {
115 $this->calendar = $a_cal;
116 }

References calendar().

+ Here is the call graph for this function:

◆ setIcal()

ilCalendarAuthenticationToken::setIcal (   $ical)

Definition at line 123 of file class.ilCalendarAuthenticationToken.php.

124 {
125 $this->ical = $ical;
126 }

References $ical.

◆ setSelectionType()

ilCalendarAuthenticationToken::setSelectionType (   $a_type)

set selection type

Parameters
int$a_type
Returns

Definition at line 103 of file class.ilCalendarAuthenticationToken.php.

104 {
105 $this->selection_type = $a_type;
106 }
$a_type
Definition: workflow.php:92

References $a_type.

◆ storeIcal()

ilCalendarAuthenticationToken::storeIcal ( )

store ical

Returns

Definition at line 151 of file class.ilCalendarAuthenticationToken.php.

152 {
153 global $DIC;
154
155 $ilDB = $DIC['ilDB'];
156
157 $ilDB->update(
158 'cal_auth_token',
159 array(
160 'ical' => array('clob',$this->getIcal()),
161 'c_time' => array('integer',time())
162 ),
163 array(
164 'user_id' => array('integer',$this->getUserId()),
165 'hash' => array('text',$this->getToken())
166 )
167 );
168 }

References $DIC, $ilDB, getIcal(), getToken(), and getUserId().

+ Here is the call graph for this function:

Field Documentation

◆ $calendar

ilCalendarAuthenticationToken::$calendar = 0
private

Definition at line 23 of file class.ilCalendarAuthenticationToken.php.

Referenced by getCalendar().

◆ $ical

ilCalendarAuthenticationToken::$ical = null
private

Definition at line 25 of file class.ilCalendarAuthenticationToken.php.

Referenced by getIcal(), and setIcal().

◆ $ical_ctime

ilCalendarAuthenticationToken::$ical_ctime = null
private

Definition at line 26 of file class.ilCalendarAuthenticationToken.php.

◆ $selection_type

ilCalendarAuthenticationToken::$selection_type = 0
private

Definition at line 22 of file class.ilCalendarAuthenticationToken.php.

Referenced by getSelectionType().

◆ $token

ilCalendarAuthenticationToken::$token = ''
private

Definition at line 21 of file class.ilCalendarAuthenticationToken.php.

Referenced by getToken().

◆ $user

ilCalendarAuthenticationToken::$user = null
private

Definition at line 19 of file class.ilCalendarAuthenticationToken.php.

Referenced by getUserId().

◆ SELECTION_CALENDAR

const ilCalendarAuthenticationToken::SELECTION_CALENDAR = 3

◆ SELECTION_CATEGORY

const ilCalendarAuthenticationToken::SELECTION_CATEGORY = 2

Definition at line 16 of file class.ilCalendarAuthenticationToken.php.

◆ SELECTION_NONE

const ilCalendarAuthenticationToken::SELECTION_NONE = 0

Definition at line 14 of file class.ilCalendarAuthenticationToken.php.

◆ SELECTION_PD

const ilCalendarAuthenticationToken::SELECTION_PD = 1

The documentation for this class was generated from the following file: