ultimix
ownership_access.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 
16  //TODO: use it somewere, in the gui::context package for example
17  //TODO: remove validation from gui::context (filters are enough)
18 
30 
41  var $Link = false;
42 
53  var $Owners = false;
54 
69  function __construct()
70  {
71  try
72  {
73  $this->Link = get_package( 'link' , 'last' , __FILE__ );
74  }
75  catch( Exception $e )
76  {
77  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
78  }
79  }
80 
111  function add_owner( $Object1Id , $Object2Id , $Object1Type , $Object2Type )
112  {
113  try
114  {
115  $this->Link->create_link( $Object1Id , $Object2Id , $Object1Type , $Object2Type , true );
116  }
117  catch( Exception $e )
118  {
119  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
120  }
121  }
122 
153  function delete_owner( $Object1Id , $Object2Id , $Object1Type , $Object2Type )
154  {
155  try
156  {
157  $this->Link->delete_link( $Object1Id , $Object2Id , $Object1Type , $Object2Type , true );
158  }
159  catch( Exception $e )
160  {
161  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
162  }
163  }
164 
187  function register_owner( $OwnerId , $OwnerType )
188  {
189  try
190  {
191  if( $this->Owners === false )
192  {
193  $this->Owners = array();
194  }
195 
196  foreach( $this->Owners as $i => $Owner )
197  {
198  if( $Owner[ 'id' ] == $OwnerId && $Owner[ 'type' ] == $OwnerType )
199  {
200  return;
201  }
202  }
203 
204  $this->Owners [] = array( 'id' => $OwnerId , 'type' => $OwnerType );
205  }
206  catch( Exception $e )
207  {
208  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
209  }
210  }
211 
234  function object_has_owner( $ObjectId , $ObjectType )
235  {
236  try
237  {
238  if( $this->Owners === false )
239  {
240  throw( new Exception( "No owners were registered" ) );
241  }
242 
243  foreach( $this->Owners as $i => $Owner )
244  {
245  if( $this->Link->link_exists( $Owner[ 'id' ] , $ObjectId , $Owner[ 'type' ] , $ObjectType ) )
246  {
247  return( true );
248  }
249  }
250 
251  return( false );
252  }
253  catch( Exception $e )
254  {
255  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
256  }
257  }
258 
285  function owner_was_registered( $ObjectId , $ObjectType )
286  {
287  try
288  {
289  if( $this->Owners === false )
290  {
291  return( false );
292  }
293 
294  foreach( $this->Owners as $i => $Owner )
295  {
296  if( $Owner[ 'id' ] == $ObjectId && $Owner[ 'type' ] == $ObjectType )
297  {
298  return( true );
299  }
300  }
301 
302  return( false );
303  }
304  catch( Exception $e )
305  {
306  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
307  }
308  }
309  }
310 
311 ?>