ultimix
group_markup.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
27 
38  var $CachedMultyFS = false;
39  var $Database = false;
40  var $GroupAccess = false;
41  var $PermitAlgorithms = false;
42  var $UserAlgorithms = false;
43 
54  var $ControllerWasAdded = false;
55 
66  function __construct()
67  {
68  try
69  {
70  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
71  $this->Database = get_package( 'database' , 'last' , __FILE__ );
72  $this->GroupAccess = get_package( 'permit::group_access' , 'last' , __FILE__ );
73  $this->PermitAlgorithms = get_package( 'permit::permit_algorithms' , 'last' , __FILE__ );
74  $this->UserAlgorithms = get_package( 'user::user_algorithms' , 'last' , __FILE__ );
75  }
76  catch( Exception $e )
77  {
78  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
79  }
80  }
81 
104  function compile_group_list( &$Settings )
105  {
106  try
107  {
108  $this->Database->query_as( DB_OBJECT );
109  $Items = $this->Database->select( 'title' , '`umx_group`' , '1' );
110  $c = count( $Items );
111  $AllGroups = '';
112  foreach( $Items as $k => $i )
113  {
114  $AllGroups .= $i->title;
115  if( $k + 1 != $c )
116  {
117  $AllGroups .= ', ';
118  }
119  }
120  return( $AllGroups );
121  }
122  catch( Exception $e )
123  {
124  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
125  }
126  }
127 
150  function compile_group_list_for_object( &$Settings )
151  {
152  try
153  {
154  $GroupList = '';
155 
156  if( $this->PermitAlgorithms->object_has_permit( false , 'user' , 'permit_manager' ) )
157  {
158  list( $Object , $Type ) = $Settings->get_settings( 'object,type' , 'public,' );
159 
160  $GroupList = $this->GroupAccess->get_groups_for_object( $Object , $Type );
161  sort( $GroupList );
162  $GroupList = implode( ', ' , $GroupList );
163  }
164 
165  return( $GroupList );
166  }
167  catch( Exception $e )
168  {
169  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
170  }
171  }
172 
195  private function get_groups( &$Settings )
196  {
197  try
198  {
199  $AllGroupList = $Settings->get_setting( 'all' , '' );
200  if( strlen( $AllGroupList ) == 0 )
201  {
202  $AllGroupList = array();
203  }
204  else
205  {
206  $AllGroupList = explode( ', ' , $AllGroupList );
207  }
208 
209  $ObjectGroupList = $Settings->get_setting( 'object_groups' , 'public' );
210  if( strlen( $ObjectGroupList ) == 0 )
211  {
212  $ObjectGroupList = array();
213  }
214  else
215  {
216  $ObjectGroupList = explode( ', ' , $ObjectGroupList );
217  }
218 
219  return( array( $ObjectGroupList , $AllGroupList ) );
220  }
221  catch( Exception $e )
222  {
223  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
224  }
225  }
226 
253  private function compile_object_groups( $ObjectGroupList , $GroupListWidget )
254  {
255  try
256  {
257  sort( $ObjectGroupList );
258 
259  foreach( $ObjectGroupList as $key => $Group )
260  {
261  $Template = $this->CachedMultyFS->get_template( __FILE__ , 'object_group.tpl' );
262  $Template = str_replace( '{group}' , $Group , $Template );
263  $GroupListWidget = str_replace( '{object_groups}' , $Template , $GroupListWidget );
264  }
265 
266  $GroupListWidget = str_replace( '{object_groups}' , '' , $GroupListWidget );
267 
268  return( $GroupListWidget );
269  }
270  catch( Exception $e )
271  {
272  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
273  }
274  }
275 
306  private function compile_all_groups( $AllGroupList , $ObjectGroupList , $GroupListWidget )
307  {
308  try
309  {
310  sort( $AllGroupList );
311 
312  foreach( $AllGroupList as $key => $Group )
313  {
314  if( in_array( $Group , $ObjectGroupList ) === false )
315  {
316  $Template = $this->CachedMultyFS->get_template( __FILE__ , 'rest_groups.tpl' );
317  $Template = str_replace( '{group}' , $Group , $Template );
318  $GroupListWidget = str_replace( '{rest_groups}' , $Template , $GroupListWidget );
319  }
320  }
321 
322  return( $GroupListWidget );
323  }
324  catch( Exception $e )
325  {
326  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
327  }
328  }
329 
352  function compile_group_list_widget( &$Settings )
353  {
354  try
355  {
356  list( $ObjectGroupList , $AllGroupList ) = $this->get_groups( $Settings );
357 
358  $GroupListWidget = $this->CachedMultyFS->get_template( __FILE__ , 'group_list.tpl' );
359  $Object = $Settings->get_setting( 'object' );
360  $GroupListWidget = str_replace( '{object}' , $Object , $GroupListWidget );
361 
362  $GroupListWidget = $this->compile_object_groups( $ObjectGroupList , $GroupListWidget );
363 
364  return( $this->compile_all_groups( $AllGroupList , $ObjectGroupList , $GroupListWidget ) );
365  }
366  catch( Exception $e )
367  {
368  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
369  }
370  }
371 
394  function compile_group_select( &$Settings )
395  {
396  try
397  {
398  list( $Name , $Class ) = $Settings->get_settings( 'name,class', 'group,flat width_160' );
399 
400  $Code = "{select:name=$Name;class=$Class;".
401  "query=SELECT id , title AS value FROM `umx_group` ORDER BY title}";
402 
403  return( $Code );
404  }
405  catch( Exception $e )
406  {
407  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
408  }
409  }
410  }
411 
412 ?>