ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMStListCompetencesSkills.php
Go to the documentation of this file.
1<?php
2
5
12{
13
17 protected $dic;
18
19
25 public function __construct(Container $dic)
26 {
27 $this->dic = $dic;
28 }
29
30
36 public function getData(array $options)
37 {
38 //Permission Filter
40
41 $select = 'SELECT sktree.title as skill_title, skill_node_id, ulvl.trigger_obj_id, user_id, login, firstname, lastname, email, lvl.title as skill_level';
42
43 $query = $select .
44 ' FROM skl_personal_skill sk ' .
45 ' INNER JOIN usr_data ud ON ud.usr_id = sk.user_id ' .
46 ' INNER JOIN skl_tree_node sktree ON sktree.obj_id = sk.skill_node_id ' .
47 ' INNER JOIN (SELECT trigger_obj_id, skill_id, MAX(level_id) AS level_id ' .
48 ' FROM skl_user_has_level WHERE self_eval = 0 GROUP BY skill_id) ulvl ON sk.skill_node_id = ulvl.skill_id ' .
49 ' INNER JOIN skl_level lvl ON lvl.id = ulvl.level_id ' .
50 ' WHERE ';
51
52 $data = [];
53 $users_per_position = ilMyStaffAccess::getInstance()->getUsersForUserPerPosition($this->dic->user()->getId());
54
55 if (empty($users_per_position)) {
56 if ($options["count"]) {
57 return 0;
58 } else {
59 return [];
60 }
61 }
62
63 $arr_query = [];
64 foreach ($users_per_position as $position_id => $users) {
65 $obj_ids = ilMyStaffAccess::getInstance()->getIdsForUserAndOperation($this->dic->user()->getId(), $operation_access);
66 $arr_query[] = $query . $this->dic->database()->in('ulvl.trigger_obj_id', $obj_ids, false, 'integer') . " AND " . $this->dic->database()->in('sk.user_id ', $users, false, 'integer')
67 . $this->getAdditionalWhereStatement($options['filters']);
68 }
69
70 $union_query = "SELECT * FROM ((" . implode(') UNION (', $arr_query) . ")) as a_table";
71
72 if ($options['count'] === true) {
73 $set = $this->dic->database()->query($union_query);
74
75 return $this->dic->database()->numRows($set);
76 }
77
78 if ($options['sort']) {
79 $union_query .= " ORDER BY " . $options['sort']['field'] . " " . $options['sort']['direction'];
80 }
81
82 if (isset($options['limit']['start']) && isset($options['limit']['end'])) {
83 $union_query .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end'];
84 }
85
86 $set = $this->dic->database()->query($union_query);
87
88 $skills = [];
89 while ($rec = $this->dic->database()->fetchAssoc($set)) {
90 $skills[] = new ilMStListCompetencesSkill(
91 $rec['skill_node_id'],
92 $rec['skill_title'],
93 $rec['skill_level'],
94 $rec['login'],
95 $rec['lastname'],
96 $rec['firstname'],
97 $rec['email'],
98 $rec['user_id']
99 );
100 }
101
102 return $skills;
103 }
104
105
111 protected function getAdditionalWhereStatement(array $filters) : string
112 {
113 $wheres = [];
114
115 if (!empty($filters['skill'])) {
116 $wheres[] = "sktree.title LIKE '%" . $filters['skill'] . "%'";
117 }
118
119 if (!empty($filters['skill_level'])) {
120 $wheres[] = "lvl.title LIKE '%" . $filters['skill_level'] . "%'";
121 }
122
123 if (!empty($filters['user'])) {
124 $wheres[] = "(" . $this->dic->database()->like("ud.login", "text", "%" . $filters['user'] . "%") . " " . "OR " . $this->dic->database()
125 ->like("ud.firstname", "text", "%" . $filters['user'] . "%") . " " . "OR " . $this->dic->database()
126 ->like("ud.lastname", "text", "%" . $filters['user'] . "%") . " " . "OR " . $this->dic->database()
127 ->like("ud.email", "text", "%" . $filters['user'] . "%") . ") ";
128 }
129
130 if (!empty($filters['org_unit'])) {
131 $wheres[] = 'ud.usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' .
132 $this->dic->database()->quote($filters['org_unit'], 'integer') . ')';
133 }
134
135 return empty($wheres) ? '' : ' AND ' . implode(' AND ', $wheres);
136 }
137}
An exception for terminatinating execution or to throw for unit testing.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:19
Class ilMStListCompetencesSkill.
Class ilMStListCompetencesSkills.
__construct(Container $dic)
ilMStListCompetencesSkills constructor.
$query
$data
Definition: storeScorm.php:23