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