ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMStListCourses.php
Go to the documentation of this file.
1 <?php
3 
6 use ilLPStatus;
8 
15 {
16 
17 
21  protected $dic;
22 
23 
29  public function __construct(Container $dic)
30  {
31  $this->dic = $dic;
32  }
33 
40  public function getData(array $arr_usr_ids = array(), array $options = array())
41  {
42  $users_per_position = ilMyStaffAccess::getInstance()->getUsersForUserPerPosition($this->dic->user()->getId());
43 
44  if (empty($users_per_position)) {
45  if ($options["count"]) {
46  return 0;
47  } else {
48  return [];
49  }
50  }
51 
52  //Permission Filter
54 
55  // permission should not be changed here because learning progress only works in combination with course memberships
56  /*if (isset($arr_filter['lp_status']) && $arr_filter['lp_status'] >= 0) {
57  $operation_access = ilOrgUnitOperation::OP_READ_LEARNING_PROGRESS;
58  }*/
59  /*$tmp_table_user_matrix = ilMyStaffAccess::getInstance()->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($this->dic->user()
60  ->getId(), $operation_access, ilMyStaffAccess::DEFAULT_CONTEXT, ilMyStaffAccess::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX);*/
61 
62  $_options = array(
63  'filters' => array(),
64  'sort' => array(),
65  'limit' => array(),
66  'count' => false,
67  );
68  $options = array_merge($_options, $options);
69 
70  $query = 'SELECT crs_ref.ref_id AS crs_ref_id, crs.title AS crs_title, reg_status, lp_status, usr_data.usr_id AS usr_id, usr_data.login AS usr_login, usr_data.lastname AS usr_lastname, usr_data.firstname AS usr_firstname, usr_data.email AS usr_email FROM (
71  SELECT reg.obj_id, reg.usr_id, ' . ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED . ' AS reg_status, lp.status AS lp_status FROM obj_members
72  AS reg
73  LEFT JOIN ut_lp_marks AS lp on lp.obj_id = reg.obj_id AND lp.usr_id = reg.usr_id
74  WHERE ' . $this->dic->database()->in('reg.usr_id', $arr_usr_ids, false, 'integer') . ' AND (reg.admin > 0 OR reg.tutor > 0 OR reg.member > 0)
75  UNION
76  SELECT obj_id, usr_id, ' . ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST . ' AS reg_status, 0 AS lp_status FROM crs_waiting_list AS waiting
77  WHERE ' . $this->dic->database()->in('waiting.usr_id', $arr_usr_ids, false, 'integer') . '
78  UNION
79  SELECT obj_id, usr_id, ' . ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED . ' AS reg_status, 0 AS lp_status FROM il_subscribers AS requested
80  WHERE ' . $this->dic->database()->in('requested.usr_id', $arr_usr_ids, false, 'integer') . '
81  ) AS memb
82 
83  INNER JOIN object_data AS crs on crs.obj_id = memb.obj_id AND crs.type = ' . $this->dic->database()
84  ->quote(ilMyStaffAccess::COURSE_CONTEXT, 'text') . '
85  INNER JOIN object_reference AS crs_ref on crs_ref.obj_id = crs.obj_id AND crs_ref.deleted IS NULL
86  INNER JOIN usr_data on usr_data.usr_id = memb.usr_id';
87 
88 
89  $arr_query = [];
90  foreach ($users_per_position as $position_id => $users) {
91  $obj_ids = ilMyStaffAccess::getInstance()->getIdsForUserAndOperation($this->dic->user()->getId(), $operation_access);
92  $arr_query[] = $query . " AND " . $this->dic->database()->in('crs.obj_id', $obj_ids, false, 'integer') . " AND " . $this->dic->database()->in('usr_data.usr_id', $users, false, 'integer');
93  }
94 
95  $union_query = "SELECT * FROM ((" . implode(') UNION (', $arr_query) . ")) as a_table";
96 
97  $union_query .= static::createWhereStatement($options['filters']);
98 
99  if ($options['count']) {
100  $result = $this->dic->database()->query($union_query);
101 
102  return $this->dic->database()->numRows($result);
103  }
104 
105  if ($options['sort']) {
106  $union_query .= " ORDER BY " . $options['sort']['field'] . " " . $options['sort']['direction'];
107  }
108 
109  if (isset($options['limit']['start']) && isset($options['limit']['end'])) {
110  $union_query .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end'];
111  }
112  $result = $this->dic->database()->query($union_query);
113  $crs_data = array();
114 
115  while ($crs = $this->dic->database()->fetchAssoc($result)) {
116  $list_course = new ilMStListCourse();
117  $list_course->setCrsRefId($crs['crs_ref_id']);
118  $list_course->setCrsTitle($crs['crs_title']);
119  $list_course->setUsrRegStatus($crs['reg_status']);
120  $list_course->setUsrLpStatus($crs['lp_status']);
121  $list_course->setUsrLogin($crs['usr_login']);
122  $list_course->setUsrLastname($crs['usr_lastname']);
123  $list_course->setUsrFirstname($crs['usr_firstname']);
124  $list_course->setUsrEmail($crs['usr_email']);
125  $list_course->setUsrId($crs['usr_id']);
126 
127  $crs_data[] = $list_course;
128  }
129 
130  return $crs_data;
131  }
132 
133 
143  protected function createWhereStatement(array $arr_filter)
144  {
145  $where = array();
146 
147 
148  if (!empty($arr_filter['crs_title'])) {
149  $where[] = '(crs_title LIKE ' . $this->dic->database()->quote('%' . $arr_filter['crs_title'] . '%', 'text') . ')';
150  }
151 
152  if ($arr_filter['course'] > 0) {
153  $where[] = '(crs_ref_id = ' . $this->dic->database()->quote($arr_filter['course'], 'integer') . ')';
154  }
155 
156  if (isset($arr_filter['lp_status']) && $arr_filter['lp_status'] >= 0) {
157  switch ($arr_filter['lp_status']) {
159  //if a user has the lp status not attempted it could be, that the user hase no records in table ut_lp_marks
160  $where[] = '(lp_status = ' . $this->dic->database()->quote($arr_filter['lp_status'], 'integer') . ' OR lp_status is NULL)';
161  break;
162  default:
163  $where[] = '(lp_status = ' . $this->dic->database()->quote($arr_filter['lp_status'], 'integer') . ')';
164  break;
165  }
166  }
167 
168  if (!empty($arr_filter['memb_status'])) {
169  $where[] = '(reg_status = ' . $this->dic->database()->quote($arr_filter['memb_status'], 'integer') . ')';
170  }
171 
172  if (!empty($arr_filter['user'])) {
173  $where[] = "(" . $this->dic->database()->like("usr_login", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
174  ->like("usr_firstname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
175  ->like("usr_lastname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $this->dic->database()
176  ->like("usr_email", "text", "%" . $arr_filter['user'] . "%") . ") ";
177  }
178 
179  if (!empty($arr_filter['org_unit'])) {
180  $where[] = 'usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . $this->dic->database()
181  ->quote($arr_filter['org_unit'], 'integer') . ')';
182  }
183 
184  if (isset($arr_filter['usr_id']) && is_numeric($arr_filter['usr_id'])) {
185  $where[] = 'usr_id = ' . $this->dic->database()->quote($arr_filter['usr_id'], \ilDBConstants::T_INTEGER);
186  }
187 
188  if (!empty($where)) {
189  return ' WHERE ' . implode(' AND ', $where) . ' ';
190  } else {
191  return '';
192  }
193  }
194 }
__construct(Container $dic)
ilMStListCourses constructor.
$result
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:18
getData(array $arr_usr_ids=array(), array $options=array())
$query
const LP_STATUS_NOT_ATTEMPTED_NUM
createWhereStatement(array $arr_filter)
Returns the WHERE Part for the Queries using parameter $user_ids AND local variable $filters...