ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 static function _getCommands()
34 {
35 $commands = array(
36 array(
37 'permission'=> 'read',
38 'cmd' => 'showThreads',
39 'lang_var' => 'show',
40 'default' => true
41 ),
42 array(
43 'permission'=> 'write',
44 'cmd' => 'edit',
45 'lang_var' => 'settings'
46 ),
47 );
48
49 return $commands;
50 }
51
58 public static function _checkGoto($a_target)
59 {
60 global $DIC;
61
62 $t_arr = explode('_', $a_target);
63
64 if ($t_arr[0] != 'frm' || ((int) $t_arr[1]) <= 0) {
65 return false;
66 }
67
68 if ($DIC->access()->checkAccess('read', '', $t_arr[1])) {
69 return true;
70 }
71
72 return false;
73 }
74
81 public static function _getThreadForPosting($a_pos_id)
82 {
83 global $DIC;
84 $ilDB = $DIC->database();
85
86 $res = $ilDB->queryF(
87 'SELECT pos_thr_fk FROM frm_posts WHERE pos_pk = %s',
88 array('integer'),
89 array($a_pos_id)
90 );
91
92 $row = $ilDB->fetchAssoc($res);
93
94 return $row['pos_thr_fk'];
95 }
96
103 public static function _lookupDiskUsage($a_obj_id)
104 {
105 global $DIC;
106 $ilDB = $DIC->database();
107
108 require_once 'Modules/Forum/classes/class.ilFileDataForum.php';
109
110 $res = $ilDB->queryf(
111 'SELECT top_frm_fk, pos_pk FROM frm_posts p
112 JOIN frm_data d ON d.top_pk = p.pos_top_fk
113 WHERE top_frm_fk = %s',
114 array('integer'),
115 array($a_obj_id)
116 );
117
118 $size = 0;
119 while ($row = $ilDB->fetchAssoc($res)) {
120 $fileDataForum = new ilFileDataForum($row['top_frm_fk'], $row['pos_pk']);
121 $filesOfPost = $fileDataForum->getFilesOfPost();
122 foreach ($filesOfPost as $attachment) {
123 $size += $attachment['size'];
124 }
125 unset($fileDataForum);
126 unset($filesOfPost);
127 }
128
129 return $size;
130 }
131
138 public static function prepareMessageForLists($text)
139 {
140 include_once 'Services/Utilities/classes/class.ilStr.php';
141
142 $text = strip_tags($text);
143 $text = preg_replace('/\[(\/)?quote\]/', '', $text);
144 if (ilStr::strLen($text) > 40) {
145 $text = ilStr::subStr($text, 0, 37) . '...';
146 }
147
148 return $text;
149 }
150
155 public static function _preloadData($obj_ids, $ref_ids)
156 {
157 /*
158 We are only able to preload the top_pk values for the forum ref_ids.
159 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
160 */
161 ilObjForum::preloadForumIdsByRefIds((array) $ref_ids);
162 }
163
169 public static function getLastPostByRefId($ref_id)
170 {
171 return ilObjForum::lookupLastPostByRefId($ref_id);
172 }
173
179 public static function getStatisticsByRefId($ref_id)
180 {
182 }
183
189 public static function getCachedUserInstance($usr_id)
190 {
191 if (!isset(self::$userInstanceCache[$usr_id]) && ilObjUser::userExists([$usr_id])) {
192 self::$userInstanceCache[$usr_id] = ilObjectFactory::getInstanceByObjId($usr_id, false);
193 }
194
195 return self::$userInstanceCache[$usr_id];
196 }
197}
$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
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$text
Definition: errorreport.php:18