ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 24 of file class.ilTreeTrashQueries.php.

Constructor & Destructor Documentation

◆ __construct()

ilTreeTrashQueries::__construct ( )

ilTreeTrash constructor.

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

40 {
41 global $DIC;
42
43 $this->db = $DIC->database();
44 $this->logger = $DIC->logger()->tree();
45 $this->tree = $DIC->repositoryTree();
46 }
global $DIC
Definition: shib_login.php:26

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

+ 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?: \ilDate, to?: \ilDate}} $filter
Returns
string

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

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

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

+ Here is the call graph for this function:

◆ findRepositoryLocationForDeletedNode()

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

ilRepositoryException

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

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

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

+ Here is the call graph for this function:

◆ getNumberOfTrashedNodesForTrashedContainer()

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

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

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

References $ref_id, and $res.

◆ getTrashedNodesForContainerUsingRecursion()

ilTreeTrashQueries::getTrashedNodesForContainerUsingRecursion ( int  $ref_id)

Unfortunately not supported by mysql 5.

Parameters
int$ref_id
Returns
void
Exceptions
ilDatabaseException
Deprecated:

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

185 : void
186 {
187 $query = 'WITH RECURSIVE trash (child,tree) AS ' .
188 '( SELECT child, tree FROM tree WHERE child = ' . $this->db->quote(
189 $ref_id,
191 ) . ' ' .
192 'UNION SELECT tc.child,tc.tree FROM tree tc JOIN tree tp ON tp.child = tc.parent ) ' .
193 'SELECT * FROM trash WHERE tree < 1 ';
194
195 $trash_ids = [];
196 try {
197 $res = $this->db->query($query);
198 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
199 $trash_ids[] = (int) $row->child;
200 }
201 } catch (\ilDatabaseException $e) {
202 $this->logger->warning($query . ' is not supported');
203 throw $e;
204 }
205 }
Class ilDatabaseException.

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

+ Here is the call graph for this function:

◆ getTrashedNodeTypesForContainer()

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

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

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

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

◆ 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

ilDatabaseException

Count query

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

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

◆ isTrashedTrash()

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

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

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

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

Field Documentation

◆ $db

ilDBInterface ilTreeTrashQueries::$db
private

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

◆ $logger

ilLogger ilTreeTrashQueries::$logger
private

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

◆ $ref_id

int ilTreeTrashQueries::$ref_id = 0
private

◆ $tree

ilTree ilTreeTrashQueries::$tree
private

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

◆ QUERY_LIMIT

const ilTreeTrashQueries::QUERY_LIMIT = 10
protected

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


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