ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCalendarAuthenticationToken Class Reference

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

+ Collaboration diagram for ilCalendarAuthenticationToken:

Public Member Functions

 __construct (int $a_user_id, string $a_token='')
 
 getSelectionType ()
 
 getUserId ()
 
 setSelectionType (int $a_type)
 
 setCalendar (int $a_cal)
 
 getCalendar ()
 
 setIcal (string $ical)
 
 getIcal ()
 
 getToken ()
 
 storeIcal ()
 
 isIcalExpired ()
 Check if cache is disabled or expired. More...
 
 add ()
 

Static Public Member Functions

static lookupAuthToken (int $a_user_id, int $a_selection, int $a_calendar=0)
 
static lookupUser (string $a_token)
 

Data Fields

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

Protected Member Functions

 createToken ()
 
 read ()
 

Protected Attributes

ilDBInterface $db
 

Private Attributes

int $user
 
string $token = ''
 
int $selection_type = self::SELECTION_NONE
 
int $calendar = 0
 
string $ical = ''
 
int $ical_ctime = 0
 

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

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

Constructor & Destructor Documentation

◆ __construct()

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

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

References $DIC, read(), and ILIAS\Repository\user().

45  {
46  global $DIC;
47 
48  $this->db = $DIC->database();
49 
50  $this->user = $a_user_id;
51  $this->token = $a_token;
52  $this->read();
53  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ add()

ilCalendarAuthenticationToken::add ( )

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

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

155  : string
156  {
157  $this->createToken();
158  $query = "INSERT INTO cal_auth_token (user_id,hash,selection,calendar) " .
159  "VALUES ( " .
160  $this->db->quote($this->getUserId(), 'integer') . ', ' .
161  $this->db->quote($this->getToken(), 'text') . ', ' .
162  $this->db->quote($this->getSelectionType(), 'integer') . ', ' .
163  $this->db->quote($this->getCalendar(), 'integer') . ' ' .
164  ')';
165  $this->db->manipulate($query);
166  return $this->getToken();
167  }
$query
+ Here is the call graph for this function:

◆ createToken()

ilCalendarAuthenticationToken::createToken ( )
protected

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

References getSelectionType(), and getUserId().

Referenced by add().

169  : void
170  {
171  $random = new \ilRandom();
172  $this->token = md5($this->getUserId() . $this->getSelectionType() . $random->int());
173  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCalendar()

ilCalendarAuthenticationToken::getCalendar ( )

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

References $calendar.

Referenced by add().

105  : int
106  {
107  return $this->calendar;
108  }
+ Here is the caller graph for this function:

◆ getIcal()

ilCalendarAuthenticationToken::getIcal ( )

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

References $ical.

Referenced by storeIcal().

115  : string
116  {
117  return $this->ical;
118  }
+ Here is the caller graph for this function:

◆ getSelectionType()

ilCalendarAuthenticationToken::getSelectionType ( )

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

References $selection_type.

Referenced by add(), and createToken().

+ Here is the caller graph for this function:

◆ getToken()

ilCalendarAuthenticationToken::getToken ( )

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

References $token.

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

120  : string
121  {
122  return $this->token;
123  }
+ Here is the caller graph for this function:

◆ getUserId()

ilCalendarAuthenticationToken::getUserId ( )

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

References $user.

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

90  : int
91  {
92  return $this->user;
93  }
+ Here is the caller graph for this function:

◆ isIcalExpired()

ilCalendarAuthenticationToken::isIcalExpired ( )

Check if cache is disabled or expired.

Todo:
enable the cache

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

References ilCalendarSettings\_getInstance().

144  : bool
145  {
146  if (!ilCalendarSettings::_getInstance()->isSynchronisationCacheEnabled()) {
147  return true;
148  }
149  if (!ilCalendarSettings::_getInstance()->getSynchronisationCacheMinutes()) {
150  return true;
151  }
152  return time() > ($this->ical_ctime + 60 * ilCalendarSettings::_getInstance()->getSynchronisationCacheMinutes());
153  }
+ Here is the call graph for this function:

◆ lookupAuthToken()

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

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

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

Referenced by ilCalendarSubscriptionGUI\createToken().

55  : string
56  {
57  global $DIC;
58 
59  $ilDB = $DIC['ilDB'];
60  $query = "SELECT * FROM cal_auth_token " .
61  "WHERE user_id = " . $ilDB->quote($a_user_id, 'integer') . ' ' .
62  "AND selection = " . $ilDB->quote($a_selection, 'integer') . ' ' .
63  "AND calendar = " . $ilDB->quote($a_calendar, 'integer');
64  $res = $ilDB->query($query);
65  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
66  return $row->hash;
67  }
68  return '';
69  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ lookupUser()

static ilCalendarAuthenticationToken::lookupUser ( string  $a_token)
static

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

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

Referenced by ilCalendarRemoteAccessHandler\initTokenHandler().

71  : int
72  {
73  global $DIC;
74 
75  $ilDB = $DIC['ilDB'];
76  $query = "SELECT * FROM cal_auth_token " .
77  "WHERE hash = " . $ilDB->quote($a_token, 'text');
78  $res = $ilDB->query($query);
79  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
80  return (int) $row->user_id;
81  }
82  return 0;
83  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ read()

ilCalendarAuthenticationToken::read ( )
protected

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

References $query, $res, ILIAS\UI\examples\Symbol\Glyph\Calendar\calendar(), ilDBConstants\FETCHMODE_OBJECT, getToken(), getUserId(), and ILIAS\Repository\int().

Referenced by __construct().

175  : bool
176  {
177  if (!$this->getToken()) {
178  $query = "SELECT * FROM cal_auth_token " .
179  "WHERE user_id = " . $this->db->quote($this->getUserId(), 'integer');
180  } else {
181  $query = 'SELECT * FROM cal_auth_token ' .
182  'WHERE user_id = ' . $this->db->quote($this->getUserId(), 'integer') . ' ' .
183  'AND hash = ' . $this->db->quote($this->getToken(), 'text');
184  }
185 
186  $res = $this->db->query($query);
187  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
188  $this->token = (string) $row->hash;
189  $this->selection_type = (int) $row->selection;
190  $this->calendar = (int) $row->calendar;
191  $this->ical = (string) $row->ical;
192  $this->ical_ctime = (int) $row->c_time;
193  }
194  return true;
195  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCalendar()

ilCalendarAuthenticationToken::setCalendar ( int  $a_cal)

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

References ILIAS\UI\examples\Symbol\Glyph\Calendar\calendar().

100  : void
101  {
102  $this->calendar = $a_cal;
103  }
+ Here is the call graph for this function:

◆ setIcal()

ilCalendarAuthenticationToken::setIcal ( string  $ical)

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

References $ical.

110  : void
111  {
112  $this->ical = $ical;
113  }

◆ setSelectionType()

ilCalendarAuthenticationToken::setSelectionType ( int  $a_type)

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

95  : void
96  {
97  $this->selection_type = $a_type;
98  }

◆ storeIcal()

ilCalendarAuthenticationToken::storeIcal ( )

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

References getIcal(), getToken(), and getUserId().

125  : void
126  {
127  $this->db->update(
128  'cal_auth_token',
129  array(
130  'ical' => array('clob', $this->getIcal()),
131  'c_time' => array('integer', time())
132  ),
133  array(
134  'user_id' => array('integer', $this->getUserId()),
135  'hash' => array('text', $this->getToken())
136  )
137  );
138  }
+ Here is the call graph for this function:

Field Documentation

◆ $calendar

int ilCalendarAuthenticationToken::$calendar = 0
private

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

Referenced by getCalendar().

◆ $db

ilDBInterface ilCalendarAuthenticationToken::$db
protected

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

◆ $ical

string ilCalendarAuthenticationToken::$ical = ''
private

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

Referenced by getIcal(), and setIcal().

◆ $ical_ctime

int ilCalendarAuthenticationToken::$ical_ctime = 0
private

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

◆ $selection_type

int ilCalendarAuthenticationToken::$selection_type = self::SELECTION_NONE
private

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

Referenced by getSelectionType().

◆ $token

string ilCalendarAuthenticationToken::$token = ''
private

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

Referenced by getToken().

◆ $user

int ilCalendarAuthenticationToken::$user
private

Definition at line 33 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 30 of file class.ilCalendarAuthenticationToken.php.

◆ SELECTION_NONE

const ilCalendarAuthenticationToken::SELECTION_NONE = 0

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

◆ SELECTION_PD

const ilCalendarAuthenticationToken::SELECTION_PD = 1

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