ILIAS  release_8 Revision v8.24
class.ilObjForumAccess.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
29 protected static array $userInstanceCache = [];
30
31 public static function _getCommands(): array
32 {
33 return [
34 [
35 'permission' => 'read',
36 'cmd' => 'showThreads',
37 'lang_var' => 'show',
38 'default' => true
39 ],
40 [
41 'permission' => 'write',
42 'cmd' => 'edit',
43 'lang_var' => 'settings'
44 ],
45 ];
46 }
47
48 public static function _checkGoto(string $target): bool
49 {
50 global $DIC;
51
52 $t_arr = explode('_', $target);
53
54 if ($t_arr[0] !== 'frm' || ((int) $t_arr[1]) <= 0) {
55 return false;
56 }
57
58 if (
59 $DIC->access()->checkAccess('read', '', (int) $t_arr[1]) ||
60 $DIC->access()->checkAccess('visible', '', (int) $t_arr[1])
61 ) {
62 return true;
63 }
64
65 return false;
66 }
67
68 public static function _getThreadForPosting(int $a_pos_id): int
69 {
70 global $DIC;
71 $ilDB = $DIC->database();
72
73 $res = $ilDB->queryF(
74 'SELECT pos_thr_fk FROM frm_posts WHERE pos_pk = %s',
75 ['integer'],
76 [$a_pos_id]
77 );
78
79 $row = $ilDB->fetchAssoc($res);
80
81 return (int) $row['pos_thr_fk'];
82 }
83
84 public static function prepareMessageForLists(string $text): string
85 {
86 $text = str_replace('<br />', ' ', $text);
87 $text = strip_tags($text);
88 $text = preg_replace('/\[(\/)?quote\]/', '', $text);
89 if (ilStr::strLen($text) > 40) {
90 $text = ilStr::subStr($text, 0, 37) . '...';
91 }
92
93 return $text;
94 }
95
96 public static function _preloadData(array $obj_ids, array $ref_ids): void
97 {
98 /*
99 We are only able to preload the top_pk values for the forum ref_ids.
100 Other data like statistics and last posts require permission checks per reference, so there is no added value for using an SQL IN() function in the queries
101 */
103 }
104
105 public static function getLastPostByRefId(int $ref_id): ?array
106 {
108 }
109
114 public static function getStatisticsByRefId(int $ref_id): array
115 {
117 }
118
119 public static function getCachedUserInstance(int $usr_id): ?ilObjUser
120 {
121 if (!isset(self::$userInstanceCache[$usr_id]) && ilObjUser::userExists([$usr_id])) {
122 $user = ilObjectFactory::getInstanceByObjId($usr_id, false);
123 if ($user instanceof ilObjUser) {
124 self::$userInstanceCache[$usr_id] = $user;
125 }
126 }
127
128 return self::$userInstanceCache[$usr_id] ?? null;
129 }
130}
return true
Class ilObjForumAccess.
static getStatisticsByRefId(int $ref_id)
static getCachedUserInstance(int $usr_id)
static _preloadData(array $obj_ids, array $ref_ids)
Preload data.
static array $userInstanceCache
static _getCommands()
get commands
static prepareMessageForLists(string $text)
static getLastPostByRefId(int $ref_id)
static _getThreadForPosting(int $a_pos_id)
static _checkGoto(string $target)
check whether goto script will succeed
static lookupStatisticsByRefId(int $ref_id)
static preloadForumIdsByRefIds(array $ref_ids)
static lookupLastPostByRefId(int $ref_id)
User class.
static userExists(array $a_usr_ids=array())
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:24
static strLen(string $a_string)
Definition: class.ilStr.php:63
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
$res
Definition: ltiservices.php:69