ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 (
66  $DIC->access()->checkAccess('read', '', $t_arr[1]) ||
67  $DIC->access()->checkAccess('visible', '', $t_arr[1])
68  ) {
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  $res = $ilDB->queryf(
109  'SELECT top_frm_fk, pos_pk FROM frm_posts p
110  JOIN frm_data d ON d.top_pk = p.pos_top_fk
111  WHERE top_frm_fk = %s',
112  array('integer'),
113  array($a_obj_id)
114  );
115 
116  $size = 0;
117  while ($row = $ilDB->fetchAssoc($res)) {
118  $fileDataForum = new ilFileDataForum($row['top_frm_fk'], $row['pos_pk']);
119  $filesOfPost = $fileDataForum->getFilesOfPost();
120  foreach ($filesOfPost as $attachment) {
121  $size += $attachment['size'];
122  }
123  unset($fileDataForum);
124  unset($filesOfPost);
125  }
126 
127  return $size;
128  }
129 
136  public static function prepareMessageForLists($text)
137  {
138  $text = str_replace('<br />', ' ', $text);
139  $text = strip_tags($text);
140  $text = preg_replace('/\[(\/)?quote\]/', '', $text);
141  if (ilStr::strLen($text) > 40) {
142  $text = ilStr::subStr($text, 0, 37) . '...';
143  }
144 
145  return $text;
146  }
147 
152  public static function _preloadData($obj_ids, $ref_ids)
153  {
154  /*
155  We are only able to preload the top_pk values for the forum ref_ids.
156  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
157  */
158  ilObjForum::preloadForumIdsByRefIds((array) $ref_ids);
159  }
160 
166  public static function getLastPostByRefId($ref_id)
167  {
168  return ilObjForum::lookupLastPostByRefId($ref_id);
169  }
170 
176  public static function getStatisticsByRefId($ref_id)
177  {
178  return ilObjForum::lookupStatisticsByRefId($ref_id);
179  }
180 
186  public static function getCachedUserInstance($usr_id)
187  {
188  if (!isset(self::$userInstanceCache[$usr_id]) && ilObjUser::userExists([$usr_id])) {
189  self::$userInstanceCache[$usr_id] = ilObjectFactory::getInstanceByObjId($usr_id, false);
190  }
191 
192  return self::$userInstanceCache[$usr_id];
193  }
194 }
static getCachedUserInstance($usr_id)
$size
Definition: RandomTest.php:84
static strLen($a_string)
Definition: class.ilStr.php:78
static _getThreadForPosting($a_pos_id)
Get thread id for posting.
static getLastPostByRefId($ref_id)
static subStr($a_str, $a_start, $a_length=null)
Definition: class.ilStr.php:15
static userExists($a_usr_ids=array())
Class ilObjForumAccess.
foreach($_POST as $key=> $value) $res
static _lookupDiskUsage($a_obj_id)
Returns the number of bytes used on the harddisk by the specified forum.
global $DIC
Definition: goto.php:24
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
This class handles all operations on files for the forum object.
global $ilDB
static _checkGoto($a_target)
Check whether goto script will succeed Comment mjansen: Cannot make this static because parent method...
static lookupStatisticsByRefId($ref_id)
static getStatisticsByRefId($ref_id)
static preloadForumIdsByRefIds(array $ref_ids)
static prepareMessageForLists($text)
Prepare message for container view.
static lookupLastPostByRefId($ref_id)
static _preloadData($obj_ids, $ref_ids)
static _getCommands()
get commands this method returns an array of all possible commands/permission combinations example: $...