ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 return (
59 $DIC->access()->checkAccess('read', '', (int) $t_arr[1]) ||
60 $DIC->access()->checkAccess('visible', '', (int) $t_arr[1])
61 );
62 }
63
64 public static function _getThreadForPosting(int $a_pos_id): int
65 {
66 global $DIC;
67 $ilDB = $DIC->database();
68
69 $res = $ilDB->queryF(
70 'SELECT pos_thr_fk FROM frm_posts WHERE pos_pk = %s',
71 ['integer'],
72 [$a_pos_id]
73 );
74
75 $row = $ilDB->fetchAssoc($res);
76
77 return (int) $row['pos_thr_fk'];
78 }
79
80 public static function prepareMessageForLists(string $text): string
81 {
82 $text = str_replace('<br />', ' ', $text);
83 $text = strip_tags($text);
84 $text = preg_replace('/\[(\/)?quote\]/', '', $text);
85 if (ilStr::strLen($text) > 40) {
86 $text = ilStr::subStr($text, 0, 37) . '...';
87 }
88
89 return $text;
90 }
91
92 public static function _preloadData(array $obj_ids, array $ref_ids): void
93 {
94 /*
95 We are only able to preload the top_pk values for the forum ref_ids.
96 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
97 */
99 }
100
101 public static function getLastPostByRefId(int $ref_id): ?array
102 {
104 }
105
109 public static function getStatisticsByRefId(int $ref_id): array
110 {
112 }
113
114 public static function getCachedUserInstance(int $usr_id): ?ilObjUser
115 {
116 if (!isset(self::$userInstanceCache[$usr_id]) && ilObjUser::userExists([$usr_id])) {
117 $user = ilObjectFactory::getInstanceByObjId($usr_id, false);
118 if ($user instanceof ilObjUser) {
119 self::$userInstanceCache[$usr_id] = $user;
120 }
121 }
122
123 return self::$userInstanceCache[$usr_id] ?? null;
124 }
125}
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=[])
Class ilObjectAccess.
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:21
static strLen(string $a_string)
Definition: class.ilStr.php:60
$ref_id
Definition: ltiauth.php:66
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26