ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTermsOfServiceAcceptanceHistoryProvider.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
13  protected function getSelectPart(array $params, array $filter) : string
14  {
15  $fields = [
16  'tos_acceptance_track.tosv_id',
17  'tos_acceptance_track.criteria',
18  'tos_acceptance_track.ts',
19  'ud.usr_id',
20  'ud.login',
21  'ud.firstname',
22  'ud.lastname',
23  '(CASE WHEN tos_documents.title IS NOT NULL THEN tos_documents.title ELSE tos_versions.title END) title',
24  'tos_versions.text',
25  ];
26 
27  return implode(', ', $fields);
28  }
29 
33  protected function getFromPart(array $params, array $filter) : string
34  {
35  $joins = [
36  'INNER JOIN tos_acceptance_track ON tos_acceptance_track.usr_id = ud.usr_id',
37  'INNER JOIN tos_versions ON tos_versions.id = tos_acceptance_track.tosv_id',
38  'LEFT JOIN tos_documents ON tos_documents.id = tos_versions.doc_id',
39  ];
40 
41  return 'usr_data ud ' . implode(' ', $joins);
42  }
43 
47  protected function getWherePart(array $params, array $filter) : string
48  {
49  $where = [];
50 
51  if (isset($filter['query']) && strlen($filter['query'])) {
52  $where[] = '(' . implode(' OR ', [
53  $this->db->like('ud.login', 'text', '%' . $filter['query'] . '%'),
54  $this->db->like('ud.firstname', 'text', '%' . $filter['query'] . '%'),
55  $this->db->like('ud.lastname', 'text', '%' . $filter['query'] . '%'),
56  $this->db->like('ud.email', 'text', '%' . $filter['query'] . '%')
57  ]) . ')';
58  }
59 
60  if (isset($filter['period']) && is_array($filter['period'])) {
61  $dateFilterParts = [];
62 
63  if (null !== $filter['period']['start']) {
64  $dateFilterParts[] = 'tos_acceptance_track.ts >= ' . $this->db->quote(
65  $filter['period']['start'],
66  'integer'
67  );
68  }
69 
70  if (null !== $filter['period']['end']) {
71  $dateFilterParts[] = 'tos_acceptance_track.ts <= ' . $this->db->quote(
72  $filter['period']['end'],
73  'integer'
74  );
75  }
76 
77  if (count($dateFilterParts) > 0) {
78  $where[] = '(' . implode(' AND ', $dateFilterParts) . ')';
79  }
80  }
81 
82  return implode(' AND ', $where);
83  }
84 
88  protected function getGroupByPart(array $params, array $filter) : string
89  {
90  return '';
91  }
92 
96  protected function getHavingPart(array $params, array $filter) : string
97  {
98  return '';
99  }
100 
104  protected function getOrderByPart(array $params, array $filter) : string
105  {
106  if (isset($params['order_field'])) {
107  if (!is_string($params['order_field'])) {
108  throw new InvalidArgumentException('Please provide a valid order field.');
109  }
110 
111  if (in_array($params['order_field'], ['lng', 'src'])) {
112  // Maybe necessary because of of migrated (from < 5.4.x) ILIAS installations
113  $params['order_field'] = 'ts';
114  }
115 
116  if (!in_array($params['order_field'], ['login', 'firstname', 'lastname', 'title', 'ts'])) {
117  throw new InvalidArgumentException('Please provide a valid order field.');
118  }
119 
120  if ($params['order_field'] == 'ts') {
121  $params['order_field'] = 'tos_acceptance_track.ts';
122  }
123 
124  if (!isset($params['order_direction'])) {
125  $params['order_direction'] = 'ASC';
126  } else {
127  if (!in_array(strtolower($params['order_direction']), ['asc', 'desc'])) {
128  throw new InvalidArgumentException('Please provide a valid order direction.');
129  }
130  }
131 
132  return $params['order_field'] . ' ' . $params['order_direction'];
133  }
134 
135  return '';
136  }
137 }