ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4include_once 'Services/Object/classes/class.ilObjectAccess.php';
5include_once 'Modules/Forum/classes/class.ilObjForum.php';
6
14{
19 protected static $userInstanceCache = array();
20
33 public function _getCommands()
34 {
35 $commands = array
36 (
37 array(
38 'permission'=> 'read',
39 'cmd' => 'showThreads',
40 'lang_var' => 'show',
41 'default' => true
42 ),
43 array(
44 'permission'=> 'write',
45 'cmd' => 'edit',
46 'lang_var' => 'settings'
47 ),
48 );
49
50 return $commands;
51 }
52
59 public function _checkGoto($a_target)
60 {
64 global $ilAccess;
65
66 $t_arr = explode('_', $a_target);
67
68 if($t_arr[0] != 'frm' || ((int)$t_arr[1]) <= 0)
69 {
70 return false;
71 }
72
73 if($ilAccess->checkAccess('read', '', $t_arr[1]))
74 {
75 return true;
76 }
77
78 return false;
79 }
80
87 public static function _getThreadForPosting($a_pos_id)
88 {
92 global $ilDB;
93
94 $res = $ilDB->queryF(
95 'SELECT pos_thr_fk FROM frm_posts WHERE pos_pk = %s',
96 array('integer'),
97 array($a_pos_id)
98 );
99
100 $row = $ilDB->fetchAssoc($res);
101
102 return $row['pos_thr_fk'];
103 }
104
111 public static function _lookupDiskUsage($a_obj_id)
112 {
116 global $ilDB;
117
118 require_once 'Modules/Forum/classes/class.ilFileDataForum.php';
119
120 $res = $ilDB->queryf(
121 'SELECT top_frm_fk, pos_pk FROM frm_posts p
122 JOIN frm_data d ON d.top_pk = p.pos_top_fk
123 WHERE top_frm_fk = %s',
124 array('integer'),
125 array($a_obj_id)
126 );
127
128 $size = 0;
129 while($row = $ilDB->fetchAssoc($res))
130 {
131 $fileDataForum = new ilFileDataForum($row['top_frm_fk'], $row['pos_pk']);
132 $filesOfPost = $fileDataForum->getFilesOfPost();
133 foreach($filesOfPost as $attachment)
134 {
135 $size += $attachment['size'];
136 }
137 unset($fileDataForum);
138 unset($filesOfPost);
139 }
140
141 return $size;
142 }
143
150 public static function prepareMessageForLists($text)
151 {
152 include_once 'Services/Utilities/classes/class.ilStr.php';
153
154 $text = strip_tags($text);
155 $text = preg_replace('/\[(\/)?quote\]/', '', $text);
156 if(ilStr::strLen($text) > 40)
157 {
158 $text = ilStr::subStr($text, 0, 37) . '...';
159 }
160
161 return $text;
162 }
163
168 public function _preloadData($obj_ids, $ref_ids)
169 {
170 /*
171 We are only able to preload the top_pk values for the forum ref_ids.
172 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
173 */
174 ilObjForum::preloadForumIdsByRefIds((array)$ref_ids);
175 }
176
182 public static function getLastPostByRefId($ref_id)
183 {
184 return ilObjForum::lookupLastPostByRefId($ref_id);
185 }
186
192 public static function getStatisticsByRefId($ref_id)
193 {
194 return ilObjForum::lookupStatisticsByRefId($ref_id);
195 }
196
202 public static function getCachedUserInstance($usr_id)
203 {
204 if(!isset(self::$userInstanceCache[$usr_id]))
205 {
206 self::$userInstanceCache[$usr_id] = ilObjectFactory::getInstanceByObjId($usr_id, false);
207 }
208
209 return self::$userInstanceCache[$usr_id];
210 }
211}
$size
Definition: RandomTest.php:79
This class handles all operations on files for the forum object.
Class ilObjForumAccess.
_preloadData($obj_ids, $ref_ids)
static getLastPostByRefId($ref_id)
static getStatisticsByRefId($ref_id)
static prepareMessageForLists($text)
Prepare message for container view.
static getCachedUserInstance($usr_id)
_getCommands()
get commands this method returns an array of all possible commands/permission combinations example: $...
Class ilObjectAccess.
_checkGoto($a_target)
check whether goto script will succeed
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static strLen($a_string)
Definition: class.ilStr.php:79
static subStr($a_str, $a_start, $a_length=NULL)
Definition: class.ilStr.php:15
$text
$ref_id
Definition: sahs_server.php:39
global $ilDB