ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTermsOfServiceAcceptanceHistoryProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  protected function getSelectPart(array $params, array $filter): string
28  {
29  $fields = [
30  'tos_acceptance_track.tosv_id',
31  'tos_acceptance_track.criteria',
32  'tos_acceptance_track.ts',
33  'ud.usr_id',
34  'ud.login',
35  'ud.firstname',
36  'ud.lastname',
37  '(CASE WHEN tos_documents.title IS NOT NULL THEN tos_documents.title ELSE tos_versions.title END) title',
38  'tos_versions.text',
39  ];
40 
41  return implode(', ', $fields);
42  }
43 
44  protected function getFromPart(array $params, array $filter): string
45  {
46  $joins = [
47  'INNER JOIN tos_acceptance_track ON tos_acceptance_track.usr_id = ud.usr_id',
48  'INNER JOIN tos_versions ON tos_versions.id = tos_acceptance_track.tosv_id',
49  'LEFT JOIN tos_documents ON tos_documents.id = tos_versions.doc_id',
50  ];
51 
52  return 'usr_data ud ' . implode(' ', $joins);
53  }
54 
55  protected function getWherePart(array $params, array $filter): string
56  {
57  $where = [];
58 
59  if (isset($filter['query']) && is_string($filter['query']) && $filter['query'] !== '') {
60  $where[] = '(' . implode(' OR ', [
61  $this->db->like('ud.login', 'text', '%' . $filter['query'] . '%'),
62  $this->db->like('ud.firstname', 'text', '%' . $filter['query'] . '%'),
63  $this->db->like('ud.lastname', 'text', '%' . $filter['query'] . '%'),
64  $this->db->like('ud.email', 'text', '%' . $filter['query'] . '%')
65  ]) . ')';
66  }
67 
68  if (isset($filter['period']) && is_array($filter['period'])) {
69  $dateFilterParts = [];
70 
71  if (null !== $filter['period']['start']) {
72  $dateFilterParts[] = 'tos_acceptance_track.ts >= ' . $this->db->quote(
73  $filter['period']['start'],
74  'integer'
75  );
76  }
77 
78  if (null !== $filter['period']['end']) {
79  $dateFilterParts[] = 'tos_acceptance_track.ts <= ' . $this->db->quote(
80  $filter['period']['end'],
81  'integer'
82  );
83  }
84 
85  if (count($dateFilterParts) > 0) {
86  $where[] = '(' . implode(' AND ', $dateFilterParts) . ')';
87  }
88  }
89 
90  return implode(' AND ', $where);
91  }
92 
93  protected function getGroupByPart(array $params, array $filter): string
94  {
95  return '';
96  }
97 
98  protected function getHavingPart(array $params, array $filter): string
99  {
100  return '';
101  }
102 
103  protected function getOrderByPart(array $params, array $filter): string
104  {
105  if (isset($params['order_field'])) {
106  if (!is_string($params['order_field'])) {
107  throw new InvalidArgumentException('Please provide a valid order field.');
108  }
109 
110  if (in_array($params['order_field'], ['lng', 'src'])) {
111  // Maybe necessary because of of migrated (from < 5.4.x) ILIAS installations
112  $params['order_field'] = 'ts';
113  }
114 
115  if (!in_array($params['order_field'], ['login', 'firstname', 'lastname', 'title', 'ts'])) {
116  throw new InvalidArgumentException('Please provide a valid order field.');
117  }
118 
119  if ($params['order_field'] === 'ts') {
120  $params['order_field'] = 'tos_acceptance_track.ts';
121  }
122 
123  if (!isset($params['order_direction'])) {
124  $params['order_direction'] = 'ASC';
125  } elseif (!in_array(strtolower($params['order_direction']), ['asc', 'desc'])) {
126  throw new InvalidArgumentException('Please provide a valid order direction.');
127  }
128 
129  return $params['order_field'] . ' ' . $params['order_direction'];
130  }
131 
132  return '';
133  }
134 }
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33