ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilUserCertificateTableProvider Class Reference
+ Collaboration diagram for ilUserCertificateTableProvider:

Public Member Functions

 __construct (ilDBInterface $database, ilLogger $logger, ilCtrl $controller, string $defaultTitle, ilCertificateObjectHelper $objectHelper=null)
 
 fetchDataSet ($userId, $params, $filter)
 

Protected Member Functions

 getOrderByPart (array $params, array $filter)
 

Private Attributes

 $database
 
 $logger
 
 $controller
 
 $objectHelper
 
 $defaultTitle
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilUserCertificateTableProvider::__construct ( ilDBInterface  $database,
ilLogger  $logger,
ilCtrl  $controller,
string  $defaultTitle,
ilCertificateObjectHelper  $objectHelper = null 
)
Parameters
ilDBInterface$database
ilLogger$logger
ilCtrl$controller
string$defaultTitle
ilCertificateObjectHelper | null$objectHelper

Definition at line 41 of file class.ilUserCertificateTableProvider.php.

References $controller, $database, $defaultTitle, $logger, and $objectHelper.

Member Function Documentation

◆ fetchDataSet()

ilUserCertificateTableProvider::fetchDataSet (   $userId,
  $params,
  $filter 
)
Parameters
$userId
$params
$filter
Returns
array

Definition at line 66 of file class.ilUserCertificateTableProvider.php.

References $data, PHPMailer\PHPMailer\$params, $query, $row, $title, and getOrderByPart().

67  {
68  $this->logger->info(sprintf('START - Fetching all active certificates for user: "%s"', $userId));
69 
70  $sql = 'SELECT
71  il_cert_user_cert.id,
72  il_cert_user_cert.obj_type,
73  il_cert_user_cert.thumbnail_image_path,
74  il_cert_user_cert.acquired_timestamp,
75  usr_data.firstname,
76  usr_data.lastname,
77  il_cert_user_cert.obj_id,
78  (CASE WHEN (object_data.title IS NULL OR LENGTH(object_data.title) = 0)
79  THEN
80  CASE WHEN (object_data_del.title IS NULL OR LENGTH(object_data_del.title) = 0)
81  THEN ' . $this->database->quote($this->defaultTitle, 'text') . '
82  ELSE object_data_del.title
83  END
84  ELSE object_data.title
85  END
86  ) as title,
87  (CASE WHEN (object_data.description IS NULL OR LENGTH(object_data.description) = 0)
88  THEN
89  CASE WHEN (object_data_del.description IS NULL OR LENGTH(object_data_del.description) = 0)
90  THEN ""
91  ELSE object_data_del.description
92  END
93  ELSE object_data.description
94  END
95  ) as description
96 FROM il_cert_user_cert
97 LEFT JOIN object_data ON object_data.obj_id = il_cert_user_cert.obj_id
98 LEFT JOIN object_data_del ON object_data_del.obj_id = il_cert_user_cert.obj_id
99 LEFT JOIN usr_data ON usr_data.usr_id = il_cert_user_cert.user_id
100 WHERE user_id = ' . $this->database->quote($userId, 'integer') . ' AND currently_active = 1';
101 
102 
103  if (array() !== $params) {
104  $sql .= $this->getOrderByPart($params, $filter);
105  }
106 
107  if (isset($params['limit'])) {
108  if (!is_numeric($params['limit'])) {
109  throw new InvalidArgumentException('Please provide a valid numerical limit.');
110  }
111 
112  if (!isset($params['offset'])) {
113  $params['offset'] = 0;
114  } else {
115  if (!is_numeric($params['offset'])) {
116  throw new InvalidArgumentException('Please provide a valid numerical offset.');
117  }
118  }
119 
120  $this->database->setLimit($params['limit'], $params['offset']);
121  }
122 
123  $query = $this->database->query($sql);
124 
125  $data = [
126  'items' => [],
127  'cnt' => 0,
128  ];
129 
130  while ($row = $this->database->fetchAssoc($query)) {
131  $title = $row['title'];
132 
133  $data['items'][] = array(
134  'id' => $row['id'],
135  'title' => $title,
136  'obj_id' => $row['obj_id'],
137  'obj_type' => $row['obj_type'],
138  'date' => $row['acquired_timestamp'],
139  'thumbnail_image_path' => $row['thumbnail_image_path'],
140  'description' => $row['description'],
141  'firstname' => $row['firstname'],
142  'lastname' => $row['lastname'],
143  );
144  }
145 
146  if (isset($params['limit'])) {
147  $cnt_sql = '
148  SELECT COUNT(*) cnt
149  FROM il_cert_user_cert
150  WHERE user_id = ' . $this->database->quote($userId, 'integer') . ' AND currently_active = 1';
151 
152  $row_cnt = $this->database->fetchAssoc($this->database->query($cnt_sql));
153 
154  $data['cnt'] = $row_cnt['cnt'];
155 
156  $this->logger->info(sprintf(
157  'All active certificates for user: "%s" total: "%s"',
158  $userId,
159  $data['cnt']
160  ));
161  } else {
162  $data['cnt'] = count($data['items']);
163  }
164 
165  $this->logger->debug(sprintf('END - Actual results:', json_encode($data)));
166 
167  return $data;
168  }
$query
$row
$data
Definition: bench.php:6
+ Here is the call graph for this function:

◆ getOrderByPart()

ilUserCertificateTableProvider::getOrderByPart ( array  $params,
array  $filter 
)
protected
Parameters
array$params
array$filter
Returns
string

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

Referenced by fetchDataSet().

176  {
177  if (isset($params['order_field'])) {
178  if (!is_string($params['order_field'])) {
179  throw new InvalidArgumentException('Please provide a valid order field.');
180  }
181 
182  if (!in_array($params['order_field'], array('date', 'id', 'title'))) {
183  throw new InvalidArgumentException('Please provide a valid order field.');
184  }
185 
186  if ($params['order_field'] == 'date') {
187  $params['order_field'] = 'acquired_timestamp';
188  }
189 
190  if (!isset($params['order_direction'])) {
191  $params['order_direction'] = 'ASC';
192  } elseif (!in_array(strtolower($params['order_direction']), array('asc', 'desc'))) {
193  throw new InvalidArgumentException('Please provide a valid order direction.');
194  }
195 
196  return ' ORDER BY ' . $params['order_field'] . ' ' . $params['order_direction'];
197  }
198 
199  return '';
200  }
+ Here is the caller graph for this function:

Field Documentation

◆ $controller

ilUserCertificateTableProvider::$controller
private

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

Referenced by __construct().

◆ $database

ilUserCertificateTableProvider::$database
private

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

Referenced by __construct().

◆ $defaultTitle

ilUserCertificateTableProvider::$defaultTitle
private

Definition at line 32 of file class.ilUserCertificateTableProvider.php.

Referenced by __construct().

◆ $logger

ilUserCertificateTableProvider::$logger
private

Definition at line 17 of file class.ilUserCertificateTableProvider.php.

Referenced by __construct().

◆ $objectHelper

ilUserCertificateTableProvider::$objectHelper
private

Definition at line 27 of file class.ilUserCertificateTableProvider.php.

Referenced by __construct().


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