60 $this->Database =
get_package(
'database' ,
'last' , __FILE__ );
61 $this->LinkDictionary =
get_package(
'link::link_dictionary' ,
'last' , __FILE__ );
62 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
105 $Object2Type , $SingleLinkOnly =
false )
109 if( $SingleLinkOnly && $this->
link_exists( $Object1Id , $Object2Id , $Object1Type , $Object2Type ) )
114 $Object1Id = $this->Security->get( $Object1Id ,
'integer' );
115 $Object2Id = $this->Security->get( $Object2Id ,
'integer' );
117 $LinkType = $this->LinkDictionary->get_link_type( $Object1Type , $Object2Type );
119 $this->Database->insert(
120 'umx_link' ,
'object1_id , object2_id , type' ,
"$Object1Id , $Object2Id , $LinkType"
122 $this->Database->commit();
124 catch( Exception $e )
165 $Object2Type , $SingleLinkOnly =
false )
169 if( is_array( $Object1Id ) )
171 foreach( $Object1Id as $k => $o1id )
173 $this->
create_link( $o1id , $Object2Id , $Object1Type , $Object2Type , $SingleLinkOnly );
176 elseif( is_array( $Object2Id ) )
178 foreach( $Object2Id as $k => $o2id )
180 $this->
create_link( $Object1Id , $o2id , $Object1Type , $Object2Type , $SingleLinkOnly );
186 $Object1Id , $Object2Id , $Object1Type , $Object2Type , $SingleLinkOnly
190 catch( Exception $e )
230 if( $ObjectId !==
false )
232 if( is_array( $ObjectId ) )
234 $ObjectId = implode(
',' , $ObjectId );
236 $ObjectId = $this->Security->get( $ObjectId ,
'integer_list' );
237 $Conditions [] =
"$FieldName IN ( $ObjectId )";
240 return( $Conditions );
242 catch( Exception $e )
286 $Conditions = array();
290 if( $Object1Type !==
false || $Object2Type !=
false )
292 $Types = $this->LinkDictionary->get_link_type( $Object1Type , $Object2Type );
293 $Conditions [] =
"type IN ( $Types )";
296 return( implode(
' AND ' , $Conditions ) );
298 catch( Exception $e )
338 function get_links( $Object1Id , $Object2Id , $Object1Type , $Object2Type )
342 $Conditions = $this->
prepare_conditions( $Object1Id , $Object2Id , $Object1Type , $Object2Type );
343 $Fields =
'umx_link.* , umx_link_dictionary.object1_type , umx_link_dictionary.object2_type';
344 $Conditions =
"umx_link.type = umx_link_dictionary.id AND $Conditions";
346 return( $this->Database->select( $Fields ,
'umx_link , umx_link_dictionary' , $Conditions ) );
348 catch( Exception $e )
384 function delete_link( $Object1Id , $Object2Id , $Object1Type , $Object2Type )
388 if( $Object1Type ===
false && $Object2Type ===
false )
390 throw(
new Exception(
"At least one type must be set" ) );
393 $Conditions = $this->
prepare_conditions( $Object1Id , $Object2Id , $Object1Type , $Object2Type );
395 $this->Database->delete(
'umx_link' , $Conditions );
396 $this->Database->commit();
398 catch( Exception $e )
442 $Conditions = $this->
prepare_conditions( $Object1Id , $Object2Id , $Object1Type , $Object2Type );
443 $Records = $this->Database->select(
'COUNT( * ) AS links_count' ,
'umx_link' , $Conditions );
445 return( isset( $Records[ 0 ] ) ===
false ? 0 :
get_field( $Records[ 0 ] ,
'links_count' ) );
447 catch( Exception $e )
487 function link_exists( $Object1Id , $Object2Id , $Object1Type , $Object2Type )
491 return( $this->
get_links_count( $Object1Id , $Object2Id , $Object1Type , $Object2Type ) > 0 );
493 catch( Exception $e )
533 function update_link( $Object1Id , $OldObject2Id , $NewObject2Id , $Object1Type , $Object2Type )
537 if( strpos( $Object1Id ,
',' ) ===
true )
539 $Object1Id = explode(
',' , $Object1Id );
543 $Object1Id = array( $Object1Id );
546 foreach( $Object1Id as $k => $id )
548 $this->
delete_link( $id , $OldObject2Id , $Object1Type , $Object2Type );
550 $this->
create_link( $id , $NewObject2Id , $Object1Type , $Object2Type );
553 catch( Exception $e )