ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTreeTrashQueries Class Reference
+ Collaboration diagram for ilTreeTrashQueries:

Public Member Functions

 __construct ()
 ilTreeTrash constructor. More...
 
 isTrashedTrash (array $ref_ids)
 
 findRepositoryLocationForDeletedNode (int $deleted_node)
 
 getTrashedNodeTypesForContainer (int $ref_id)
 
 getNumberOfTrashedNodesForTrashedContainer (int $ref_id)
 
 getTrashNodeForContainer (int $ref_id, array $filter, int &$max_entries, string $order_field, string $order_direction, int $limit=self::QUERY_LIMIT, int $offset=0)
 Get trashed nodes. More...
 
 getTrashedNodesForContainerUsingRecursion (int $ref_id)
 Unfortunately not supported by mysql 5. More...
 

Protected Member Functions

 appendTrashNodeForContainerQueryFilter (array $filter)
 

Protected Attributes

const QUERY_LIMIT = 10
 

Private Attributes

int $ref_id = 0
 
ilTree $tree
 
ilLogger $logger
 
ilDBInterface $db
 

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 25 of file class.ilTreeTrashQueries.php.

Constructor & Destructor Documentation

◆ __construct()

ilTreeTrashQueries::__construct ( )

ilTreeTrash constructor.

Definition at line 40 of file class.ilTreeTrashQueries.php.

References $DIC, and ILIAS\Repository\logger().

41  {
42  global $DIC;
43 
44  $this->db = $DIC->database();
45  $this->logger = $DIC->logger()->tree();
46  $this->tree = $DIC->repositoryTree();
47  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ appendTrashNodeForContainerQueryFilter()

ilTreeTrashQueries::appendTrashNodeForContainerQueryFilter ( array  $filter)
protected
Parameters
array{type?string, title?: string, deleted?: array{from?: , to?: }} $filter
Returns
string

Definition at line 212 of file class.ilTreeTrashQueries.php.

References $query, ilObjUser\_lookupId(), IL_CAL_DATE, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by getTrashNodeForContainer().

212  : string
213  {
214  $query = '';
215  if (isset($filter['type'])) {
216  $query .= 'and ' . $this->db->like(
217  'type',
219  $filter['type']
220  ) . ' ';
221  }
222  if (isset($filter['title'])) {
223  $query .= 'and ' . $this->db->like(
224  'title',
226  '%' . $filter['title'] . '%'
227  ) . ' ';
228  }
229 
230  // #33781 use an explizit date format to really include the 'to' date because it can be interpreted as 'xxxx-xx-xx 00:00:00'
231  if (
232  $filter['deleted']['from'] instanceof \ilDate &&
233  $filter['deleted']['to'] instanceof \ilDate) {
234  $query .= ('AND deleted BETWEEN ' .
235  $this->db->quote($filter['deleted']['from']->get(\IL_CAL_DATE), \ilDBConstants::T_TEXT) . ' AND ' .
236  $this->db->quote($filter['deleted']['to']->get(IL_CAL_DATE) . " 23:59:59", \ilDBConstants::T_TEXT) . ' ');
237  } elseif ($filter['deleted']['from'] instanceof \ilDate) {
238  $query .= 'AND deleted >= ' . $this->db->quote(
239  $filter['deleted']['from']->get(IL_CAL_DATE),
241  ) . ' ';
242  } elseif ($filter['deleted']['to'] instanceof \ilDate) {
243  $query .= 'AND deleted <= ' . $this->db->quote(
244  $filter['deleted']['to']->get(IL_CAL_DATE) . " 23:59:59",
246  ) . ' ';
247  }
248 
249  if (isset($filter['deleted_by']) && !empty($filter['deleted_by'])) {
250  $usr_id = \ilObjUser::_lookupId($filter['deleted_by']);
251  if ($usr_id > 0) {
252  $query .= 'AND deleted_by = ' . $this->db->quote($usr_id, \ilDBConstants::T_INTEGER) . ' ';
253  } else {
254  $query .= 'AND 1=2 ';
255  }
256  }
257 
258  return $query;
259  }
static _lookupId($a_user_str)
$query
const IL_CAL_DATE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findRepositoryLocationForDeletedNode()

ilTreeTrashQueries::findRepositoryLocationForDeletedNode ( int  $deleted_node)
Parameters
int$deleted_node
Returns
int $rep_ref_id
Exceptions

Definition at line 75 of file class.ilTreeTrashQueries.php.

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, ILIAS\Repository\logger(), and ilDBConstants\T_INTEGER.

75  : int
76  {
77  $query = 'select parent from tree ' .
78  'where child = ' . $this->db->quote($deleted_node, \ilDBConstants::T_INTEGER) . ' ' .
79  'and tree = ' . $this->db->quote($deleted_node * -1, \ilDBConstants::T_INTEGER);
80  $this->logger->debug($query);
81  $res = $this->db->query($query);
82  while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
83  return (int) $row->parent;
84  }
85  $this->logger->warning('Invalid node given for restoring to original location: deleted node id: ' . $deleted_node);
86  throw new \ilRepositoryException('Invalid node given for restoring to original location');
87  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:

◆ getNumberOfTrashedNodesForTrashedContainer()

ilTreeTrashQueries::getNumberOfTrashedNodesForTrashedContainer ( int  $ref_id)
Parameters
int$ref_id
Returns
int

Definition at line 114 of file class.ilTreeTrashQueries.php.

References $res.

114  : int
115  {
116  $res = $this->db->query($this->tree->getTrashSubTreeQuery($ref_id, ['child']));
117  return $res->numRows();
118  }
$res
Definition: ltiservices.php:69

◆ getTrashedNodesForContainerUsingRecursion()

ilTreeTrashQueries::getTrashedNodesForContainerUsingRecursion ( int  $ref_id)

Unfortunately not supported by mysql 5.

Parameters
int$ref_id
Returns
void
Exceptions
ilDatabaseException
Deprecated:

Definition at line 186 of file class.ilTreeTrashQueries.php.

References Vendor\Package\$e, $query, $res, ilDBConstants\FETCHMODE_OBJECT, ILIAS\Repository\int(), ILIAS\Repository\logger(), and ilDBConstants\T_INTEGER.

186  : void
187  {
188  $query = 'WITH RECURSIVE trash (child,tree) AS ' .
189  '( SELECT child, tree FROM tree WHERE child = ' . $this->db->quote(
190  $ref_id,
192  ) . ' ' .
193  'UNION SELECT tc.child,tc.tree FROM tree tc JOIN tree tp ON tp.child = tc.parent ) ' .
194  'SELECT * FROM trash WHERE tree < 1 ';
195 
196  $trash_ids = [];
197  try {
198  $res = $this->db->query($query);
199  while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
200  $trash_ids[] = (int) $row->child;
201  }
202  } catch (\ilDatabaseException $e) {
203  $this->logger->warning($query . ' is not supported');
204  throw $e;
205  }
206  }
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query
+ Here is the call graph for this function:

◆ getTrashedNodeTypesForContainer()

ilTreeTrashQueries::getTrashedNodeTypesForContainer ( int  $ref_id)
Parameters
int$ref_id
Returns
string[]

Definition at line 93 of file class.ilTreeTrashQueries.php.

References $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

93  : array
94  {
95  $subtreequery = $this->tree->getTrashSubTreeQuery($ref_id, ['child']);
96  $query = 'select distinct(type) obj_type from object_data obd ' .
97  'join object_reference obr on obd.obj_id = obr.obj_id ' .
98  'where ref_id in (' .
99  $subtreequery . ' ' .
100  ') ';
101 
102  $obj_types = [];
103  $res = $this->db->query($query);
104  while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
105  $obj_types[] = (string) $row->obj_type;
106  }
107  return $obj_types;
108  }
$res
Definition: ltiservices.php:69
$query

◆ getTrashNodeForContainer()

ilTreeTrashQueries::getTrashNodeForContainer ( int  $ref_id,
array  $filter,
int &  $max_entries,
string  $order_field,
string  $order_direction,
int  $limit = self::QUERY_LIMIT,
int  $offset = 0 
)

Get trashed nodes.

Returns
ilTreeTrashItem[]
Exceptions

Count query

Definition at line 125 of file class.ilTreeTrashQueries.php.

References $query, $res, appendTrashNodeForContainerQueryFilter(), ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

133  : array {
134  $subtreequery = $this->tree->getTrashSubTreeQuery($ref_id, ['child']);
135 
136  $select = 'SELECT ref_id, obd.obj_id, type, title, description, deleted, deleted_by ';
137  $select_count = 'SELECT COUNT(ref_id) max_entries ';
138 
139  $from = 'FROM object_data obd ' .
140  'JOIN object_reference obr ON obd.obj_id = obr.obj_id ' .
141  'WHERE ref_id IN (' .
142  $subtreequery . ' ' .
143  ') ';
144 
145  $order = ' ';
146  if ($order_field) {
147  $order = 'ORDER BY ' . $order_field . ' ' . $order_direction;
148  }
149 
150  $query = $select . $from . $this->appendTrashNodeForContainerQueryFilter($filter) . $order;
151  $query_count = $select_count . $from . $this->appendTrashNodeForContainerQueryFilter($filter);
152 
156  $res_max_entries = $this->db->query($query_count);
157  while ($max_entries_row = $res_max_entries->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
158  $max_entries = (int) $max_entries_row->max_entries;
159  }
160 
161  $this->db->setLimit($limit, $offset);
162  $res = $this->db->query($query);
163 
164  $items = [];
165  while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
166  $item = new \ilTreeTrashItem();
167  $item->setObjId((int) $row->obj_id);
168  $item->setRefId((int) $row->ref_id);
169  $item->setTitle((string) $row->title);
170  $item->setDescription((string) $row->description);
171  $item->setType((string) $row->type);
172  $item->setDeleted((string) $row->deleted);
173  $item->setDeletedBy((int) $row->deleted_by);
174  $items[] = $item;
175  }
176  return $items;
177  }
$res
Definition: ltiservices.php:69
appendTrashNodeForContainerQueryFilter(array $filter)
$query
+ Here is the call graph for this function:

◆ isTrashedTrash()

ilTreeTrashQueries::isTrashedTrash ( array  $ref_ids)
Parameters
int[]$ref_ids
Returns
bool

Definition at line 53 of file class.ilTreeTrashQueries.php.

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, ILIAS\Repository\int(), and ilDBConstants\T_INTEGER.

53  : bool
54  {
55  $query = 'select tree,child,parent from tree ' .
56  'where ' . $this->db->in('child', $ref_ids, false, \ilDBConstants::T_INTEGER);
57  $res = $this->db->query($query);
58  $trashed_trash = false;
59  while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
60  if ((int) $row->child != ((int) $row->tree * -1)) {
61  $trashed_trash = true;
62  }
63  if ($this->tree->isDeleted((int) $row->parent)) {
64  $trashed_trash = true;
65  }
66  }
67  return $trashed_trash;
68  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilTreeTrashQueries::$db
private

Definition at line 35 of file class.ilTreeTrashQueries.php.

◆ $logger

ilLogger ilTreeTrashQueries::$logger
private

Definition at line 33 of file class.ilTreeTrashQueries.php.

◆ $ref_id

int ilTreeTrashQueries::$ref_id = 0
private

Definition at line 29 of file class.ilTreeTrashQueries.php.

◆ $tree

ilTree ilTreeTrashQueries::$tree
private

Definition at line 31 of file class.ilTreeTrashQueries.php.

◆ QUERY_LIMIT

const ilTreeTrashQueries::QUERY_LIMIT = 10
protected

Definition at line 27 of file class.ilTreeTrashQueries.php.


The documentation for this class was generated from the following file: