ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjForumAccess.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
16 protected static $userInstanceCache = array();
17
30 public static function _getCommands()
31 {
32 $commands = array(
33 array(
34 'permission' => 'read',
35 'cmd' => 'showThreads',
36 'lang_var' => 'show',
37 'default' => true
38 ),
39 array(
40 'permission' => 'write',
41 'cmd' => 'edit',
42 'lang_var' => 'settings'
43 ),
44 );
45
46 return $commands;
47 }
48
55 public static function _checkGoto($a_target)
56 {
57 global $DIC;
58
59 $t_arr = explode('_', $a_target);
60
61 if ($t_arr[0] != 'frm' || ((int) $t_arr[1]) <= 0) {
62 return false;
63 }
64
65 if ($DIC->access()->checkAccess('read', '', $t_arr[1])) {
66 return true;
67 }
68
69 return false;
70 }
71
78 public static function _getThreadForPosting($a_pos_id)
79 {
80 global $DIC;
81 $ilDB = $DIC->database();
82
83 $res = $ilDB->queryF(
84 'SELECT pos_thr_fk FROM frm_posts WHERE pos_pk = %s',
85 array('integer'),
86 array($a_pos_id)
87 );
88
89 $row = $ilDB->fetchAssoc($res);
90
91 return $row['pos_thr_fk'];
92 }
93
100 public static function _lookupDiskUsage($a_obj_id)
101 {
102 global $DIC;
103 $ilDB = $DIC->database();
104
105 $res = $ilDB->queryf(
106 'SELECT top_frm_fk, pos_pk FROM frm_posts p
107 JOIN frm_data d ON d.top_pk = p.pos_top_fk
108 WHERE top_frm_fk = %s',
109 array('integer'),
110 array($a_obj_id)
111 );
112
113 $size = 0;
114 while ($row = $ilDB->fetchAssoc($res)) {
115 $fileDataForum = new ilFileDataForum($row['top_frm_fk'], $row['pos_pk']);
116 $filesOfPost = $fileDataForum->getFilesOfPost();
117 foreach ($filesOfPost as $attachment) {
118 $size += $attachment['size'];
119 }
120 unset($fileDataForum);
121 unset($filesOfPost);
122 }
123
124 return $size;
125 }
126
133 public static function prepareMessageForLists($text)
134 {
135 $text = str_replace('<br />', ' ', $text);
136 $text = strip_tags($text);
137 $text = preg_replace('/\[(\/)?quote\]/', '', $text);
138 if (ilStr::strLen($text) > 40) {
139 $text = ilStr::subStr($text, 0, 37) . '...';
140 }
141
142 return $text;
143 }
144
149 public static function _preloadData($obj_ids, $ref_ids)
150 {
151 /*
152 We are only able to preload the top_pk values for the forum ref_ids.
153 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
154 */
155 ilObjForum::preloadForumIdsByRefIds((array) $ref_ids);
156 }
157
163 public static function getLastPostByRefId($ref_id)
164 {
165 return ilObjForum::lookupLastPostByRefId($ref_id);
166 }
167
173 public static function getStatisticsByRefId($ref_id)
174 {
176 }
177
183 public static function getCachedUserInstance($usr_id)
184 {
185 if (!isset(self::$userInstanceCache[$usr_id]) && ilObjUser::userExists([$usr_id])) {
186 self::$userInstanceCache[$usr_id] = ilObjectFactory::getInstanceByObjId($usr_id, false);
187 }
188
189 return self::$userInstanceCache[$usr_id];
190 }
191}
$size
Definition: RandomTest.php:84
An exception for terminatinating execution or to throw for unit testing.
This class handles all operations on files for the forum object.
Class ilObjForumAccess.
static _getCommands()
get commands this method returns an array of all possible commands/permission combinations example: $...
static getLastPostByRefId($ref_id)
static getStatisticsByRefId($ref_id)
static prepareMessageForLists($text)
Prepare message for container view.
static _getThreadForPosting($a_pos_id)
Get thread id for posting.
static _lookupDiskUsage($a_obj_id)
Returns the number of bytes used on the harddisk by the specified forum.
static _preloadData($obj_ids, $ref_ids)
static getCachedUserInstance($usr_id)
static _checkGoto($a_target)
Check whether goto script will succeed Comment mjansen: Cannot make this static because parent method...
static preloadForumIdsByRefIds(array $ref_ids)
static lookupStatisticsByRefId($ref_id)
static lookupLastPostByRefId($ref_id)
static userExists($a_usr_ids=array())
Class ilObjectAccess.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static subStr($a_str, $a_start, $a_length=null)
Definition: class.ilStr.php:15
static strLen($a_string)
Definition: class.ilStr.php:78
$row
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$text
Definition: errorreport.php:18